Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get a press event on a parent layout?
    primarykey
    data
    text
    <p>I'm working on Android 2.2.3. I have a Button inside a FrameLayout, so that the button covers the entire FrameLayout.</p> <p>When i press the button only the button's selector gets the event of pressing. The frame's selector dose not get this event since the button is on top of it. i.e: the attribute "android:state_pressed="true" happens for the button and not for the frame.</p> <p>i need the press event and not the click event. </p> <p>I would like to make the frame's selector to be set to android:state_pressed="true" when the button is pressed. </p> <p>I've tried using </p> <pre><code>mMuteBtn.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { mFrameMute.setPressed(true); } if (event.getAction() == MotionEvent.ACTION_UP) { mFrameMute.setPressed(false); } return false; } }); </code></pre> <p>but <strong><em>it blocked the onClick() event</em></strong> which I also need for some other work. </p> <p><strong>My main.xml file is:</strong> </p> <pre><code> &lt;FrameLayout android:id="@+id/frame_mute1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/selector_background" &gt; &lt;Button android:id="@+id/mute_btn1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" android:drawableTop="@drawable/selector_button" android:text="mute" android:textColor="@android:color/black" android:textSize="12sp" /&gt; &lt;/FrameLayout&gt; </code></pre> <p><strong>The selector_background:</strong></p> <pre><code>&lt;item android:drawable="@drawable/bg2" android:state_pressed="true"/&gt; &lt;item android:drawable="@drawable/bg3" android:state_selected="true"/&gt; &lt;!-- default --&gt; &lt;item android:drawable="@drawable/bg1"/&gt; </code></pre> <p></p> <p><strong>The selector_button:</strong> </p> <pre><code>&lt;item android:drawable="@drawable/image2" android:state_pressed="true"/&gt; &lt;item android:drawable="@drawable/image3" android:state_selected="true"/&gt; &lt;!-- default --&gt; &lt;item android:drawable="@drawable/image1"/&gt; </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload