<?xml version="1.0" encoding="UTF-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:color="@color/white" /> <item android:state_checked="true" android:color="@color/white" /> <item android:color="@color/black" /> </selector>
官方對各個state屬性的介紹如下:
android:constantSize
If true, the drawable's reported internal size will remain constant as the state changes; the size is the maximum of all of the states.
android:state_activated
State value for StateListDrawable, set when a view or its parent has been "activated" meaning the user has currently marked it as being of interest.
android:state_active
State value for StateListDrawable.
android:state_checkable
State identifier indicating that the object may display a check mark.
android:state_checked
State identifier indicating that the object is currently checked.
android:state_enabled
State value for StateListDrawable, set when a view is enabled.
android:state_first
State value for StateListDrawable.
android:state_focused
State value for StateListDrawable, set when a view has input focus.
android:state_last
State value for StateListDrawable.
android:state_middle
State value for StateListDrawable.
android:state_pressed
State value for StateListDrawable, set when the user is pressing down in a view.
android:state_selected
State value for StateListDrawable, set when a view (or one of its parents) is currently selected.
android:state_single
State value for StateListDrawable.
android:state_window_focused
State value for StateListDrawable, set when a view's window has input focus.
android:variablePadding
If true, allows the drawable's padding to change based on the current state that is selected.
android:visible
Indicates whether the drawable should be initially visible.
注意:如果有多個item,那么程序將自動從上到下進行匹配,最先匹配的將得到應用。(不是通過最佳匹配)
如果一個item沒有任何的狀態說明,那么它將可以被任何一個狀態匹配。