原文链接:http://developer.android.com/guide/topics/ui/controls/button.html
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_pressed"
android:state_pressed="true" />
<item android:drawable="@drawable/button_focused"
android:state_focused="true" />
<item android:drawable="@drawable/button_default" />
</selector>
Note: The order of the <item>
elements is important. When this drawable is referenced, the <item>
elements are traversed in-order to determine which one is appropriate for the current button state. Because the default bitmap is last, it is only applied when the conditions android:state_pressed
andandroid:state_focused
have both evaluated as false.
注意: <item> 元素的顺序非常重要。当这个 drawable 被引用时,<item> 元素会以中序(in-order)的方式被遍历,以确定哪个比较恰当地对应当前的 button 状态。由于 默认bitmap 是最后面的,只有当条件 android:state_pressed 和 android:state_focused 同时为 false 时,才会使用到它