<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>
测试结果:
普通键 ->@drawable/key
普通按键按下 ->@drawable/key_pressed
粘滞键->@drawable/key_function
按下粘滞键 ->@drawable/key_function <---问题出在这里
最佳答案
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
所以它是错误的可绘制对象,因为其中一个状态与当前状态匹配
<item
android:state_checkable="true"
android:drawable="@drawable/key_function" />
<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" />
在顶部或为以前的案例添加标准。
关于android - 键盘背景状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12342357/