Note that there are some explanatory texts on larger screens.

plurals
  1. POImageButton Selectors don't fire the state_pressed when are clicked in the state_selected
    primarykey
    data
    text
    <p>I couldn't find a solution to this yet.</p> <p>I have a mute/unmute button. I set it up as an ImageButton, with both src and background being selector drawables.</p> <p>I am displaying - the "muted" icon when the button is selected - the "mute" icon when the button is not selected</p> <p>When the button is clicked I would like to display a yellow background for a fraction of a second but what I experience is that: the yellow background appears (by clicking) only when the button is not selected (isSelected=false), and it doesn't appear when the button is selected (isSelected=false)</p> <p>I don't understand why, but that's what happens!</p> <p>The yellow background does appear when the button is kept pressed (no matter whether is selected or not), but what I am really interested in is to make it appear when you just click on it without the need of keeping it pressed</p> <p>any solution?</p> <p>view.java</p> <pre><code>volumemuteImageButton = (ImageButton) findViewById(R.id.volume_mute); volumemuteImageButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { volumemuteImageButton.setSelected(!volumemuteImageButton.isSelected()); } }); </code></pre> <p>layout.xml</p> <pre><code>&lt;ImageButton android:id="@+id/volume_mute" android:layout_width="58dp" android:layout_height="fill_parent" android:src="@drawable/img_selector" android:background="@drawable/bg_selector" /&gt; </code></pre> <p>img_selector.png</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:drawable="@drawable/sdmp_ic_muted_pressed" android:state_selected="true" android:state_pressed="true" /&gt; &lt;item android:drawable="@drawable/sdmp_ic_muted_pressed" android:state_selected="true" android:state_focused="true" /&gt; &lt;item android:drawable="@drawable/sdmp_ic_muted_default" android:state_selected="true" /&gt; &lt;item android:drawable="@drawable/sdmp_ic_mute_pressed" android:state_selected="false" android:state_pressed="true" /&gt; &lt;item android:drawable="@drawable/sdmp_ic_mute_pressed" android:state_selected="false" android:state_focused="true" /&gt; &lt;item android:drawable="@drawable/sdmp_ic_mute_default" android:state_selected="false" /&gt; &lt;/selector&gt; </code></pre> <p>bg_selector.png</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:drawable="@drawable/sdmp_color_yellow" android:state_pressed="true" /&gt; &lt;item android:drawable="@drawable/sdmp_color_yellow" android:state_focused="true" /&gt; &lt;/selector&gt; </code></pre>
    singulars
    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