I have a drawable state list selector that needs to display a different drawable when selected.
I extended the View class that uses the drawable with interface Checkable
and this works ok.
However, when I only filter on state_checkable
, it displays the image for the value of false. I assume this means that there is something wrong with my implementation.
<item android:drawable="@drawable/button_6_default" android:state_checkable="false" />
<item android:drawable="@drawable/button_disable_default" android:state_checkable="true" />
How do you get state_checkable
and state_checked
to work properly?
I figured it out. You need to implement onCreateDrawableState
and add the state_checked attr if the view is checked after calling super with an increased count of the number of extra attributes you have added. Don't have the code right here anymore, sorry.