I am trying to setup a selector drawable in my asset file like this: * 2 different images for 'on'/'off' mode in rest mode (i.e. it does not has focus) * another 2 different images for 'on'/'off' mode in focus mode (i.e. it has the focus).
In my case, the 'rest' mode works, but the 'focus' mode does not.
Can you please tell me what am I missing in the focus mode? Thank you.
<!-- these 2 images works --->
<item android:state_checked="false" android:drawable="@drawable/off" />
<item android:state_checked="true" android:drawable="@drawable/on" />
<!-- these 2 images does not work -->
<item android:state_focused="true" android:state_checked="false"
android:drawable="@drawable/off_focus" />
<item android:state_focused="true" android:state_checked="true"
android:drawable="@drawable/on_focus" />
I don't believe that instances of ImageView are focusable by default, meaning that they would never take focus and your selector would never be triggered. In the place where you define your ImageView you need to set it to be focusable, see these methods: setFocusable and setFocusableInTouchMode. It can be set from XML or in code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With