Reputation: 3496
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/key" />
<item
android:state_pressed="true"
android:drawable="@drawable/key_pressed" />
<item
android:state_checkable="true"
android:drawable="@drawable/key_function" />
<item
android:state_checkable="true"
android:state_pressed="true"
android:drawable="@drawable/key_pressed" />
<item
android:state_checkable="true"
android:state_checked="true"
android:drawable="@drawable/key_function" />
<item
android:state_checkable="true"
android:state_checked="true"
android:state_pressed="true"
android:drawable="@drawable/key_pressed" />
</selector>
test result:
normal key ->@drawable/key
normal key pressed ->@drawable/key_pressed
Sticky key->@drawable/key_function
Sticky key pressed ->@drawable/key_function <---here is the problem
Upvotes: 2
Views: 632
Reputation: 5643
The selection is not based on the "best match," but simply the first item that meets the minimum criteria of the state.
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
So it's the wrong drawable because one of those states is matching the current state
<item
android:state_checkable="true"
android:drawable="@drawable/key_function" />
<item
android:state_checkable="true"
android:state_checked="true"
android:drawable="@drawable/key_function" />
Try to put
<item
android:state_checkable="true"
android:state_checked="true"
android:state_pressed="true"
android:drawable="@drawable/key_pressed" />
at the top or add criterias to the previous cases.
Upvotes: 1