ImageButton selector not working?

I am trying to make ImageButton for clicked, focused and normal state. I read the introduction of ImageButton here

I saved the XML selector file in / res / drawable /. Also install 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 did the right ImageButton. But that did not work for me.

What is wrong here?

Please advice.

+3
source share
2 answers

Items must be ordered. Thus, pressing first is focused, and the last is the default item

Contact here

+5
source

You're wrong. Try it.

android:background="@drawable/your_selector_name"
0
source

Source: https://habr.com/ru/post/1731179/


All Articles