0

I tried the following link But state_focused didn't work.

checkbox_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/checked" android:state_checked="true"/>
    <item android:drawable="@drawable/unchecked" android:state_checked="false"/>

    <item android:state_checked="true" android:state_focused="false" android:drawable="@drawable/unchecked_focus"/>
 <item android:state_checked="false" android:state_focused="true"  android:drawable="@drawable/unchecked_focus" />
</selector>

In my class, I add like this.

cbx.setButtonDrawable(R.drawable.checkbox_selector);

unchecked focused checked

First is unchecked state, second is focused state and last is for checked state. I have also tried android:state_pressed but it didn't work. Is there another way to do it?

Thanks.

Community
  • 1
  • 1
user1156041
  • 2,155
  • 5
  • 24
  • 54

1 Answers1

1

from the docs:

During each state change, the state list is traversed top to bottom and the first item that matches the current state is used—the selection is not based on the "best match," but simply the first item that meets the minimum criteria of the state.

so your item will be shown in either "checked" or "not checked" state, is it what you see?

pskink
  • 23,874
  • 6
  • 66
  • 77