state_pressed,state_checked,state_pressed,state_selected,state_focused,state_enabled 等幾個狀態:
android:state_pressed
如果是true,當被點擊時顯示該圖片,如果是false沒被按下時顯示預設。
android:state_focused
true,獲得焦點時顯示;false,沒獲得焦點顯示預設。
android:state_selected
true,當被選擇時顯示該圖片;false,當未被選擇時顯示該圖片。
android:state_checkable
true,當CheckBox能使用時顯示該圖片;false,當CheckBox不能使用時顯示該圖片。
android:state_checked
true,當CheckBox選中時顯示該圖片;false,當CheckBox為選中時顯示該圖片。
android:state_enabled
true,當該組件能使用時顯示該圖片;false,當該組件不能使用時顯示該圖片。
android:state_window_focused
true,當此activity獲得焦點在最前面時顯示該圖片;false,當沒在最前面時顯示該圖片。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/button_pressed"/><!--
pressed -->
<item android:state_focused="true"
android:drawable="@drawable/button_focused"/><!--
focused -->
<item android:drawable="@drawable/button_normal"/><!--
default -->
</selector>