Android – ImageButton selector doesn’t work

androidimagebutton

I am trying to make ImageButton for state of pressed, focused and normal.
I've read introduction of ImageButton here

I've saved selector XML file in /res/drawable/. Also set the android:src="@drawable/my_selector".

my_selector.xml file :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/btn_unfocus" /> <!-- default -->
    <item android:state_pressed="true"
          android:drawable="@drawable/btn_onpress" /> <!-- pressed -->
    <item android:state_focused="true"
          android:drawable="@drawable/btn_onfocus" /> <!-- focused -->
</selector>

I think I've done correct ImageButton. But it didn't work for me.

What is wrong here ?

Please advice.

Best Answer

Item tags should be ordered. So pressed first, focused, and the last is default item

Refer Here

Related Topic