键盘背景状态

时间:2012-09-09 19:46:33

标签: android background keyboard

<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>

测试结果:

普通键 - &gt; @ drawable / key

正常按键 - >&gt; @ drawable / key_pressed

粘滞键 - &gt; @ drawable / key_function

按下粘滞键 - &gt; @ drawable / key_function&lt; ---这里是问题

1 个答案:

答案 0 :(得分:1)

  

选择不是基于“最佳匹配”,而是基于第一个   满足国家最低标准的项目。

http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

所以这是错误的drawable,因为其中一个状态匹配当前状态

<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" />

位于顶部或为之前的案例添加标准。