The Drawable object that we can define through XML when we define a drawable. It allows a picture to display different patterns in different states, such as a button, it has a pressed,focused, or other state, and by using the state list drawable, you can provide a different picture for each of the States.
Let's look at an example:
XML file saved at res/drawable/button.xml
:
[Java]View PlainCopy
- <?xml version="1.0" encoding="Utf-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android" >
- <item android:state_pressed="true" android:state_enabled="true" android:state_window_focused=" False "
- android:drawable="@drawable/button_pressed"/> <!--pressed,enable Multiple properties --
- <item android:state_focused="true"
- android:drawable="@drawable/button_focused"/> <!--focused --
- <item android:state_hovered="true"
- android:drawable="@drawable/button_focused"/> <!--hovered --
- <item android:drawable="@drawable/button_normal"/> <!-- default ---
- </selector>
This layout XML applies the state list drawable to a Button:
[Java]View PlainCopy
- <BUTTON&NBSP;&NBSP;
- android: Layout_height= "wrap_content" &NBSP;&NBSP;
- android:layout_width= "wrap_content" &NBSP;&NBSP;
- android:background= "@drawable/button" &NBSP;/>&NBSP;&NBSP;
Android:drawable put a drawable resource
Whether the android:state_pressed is pressed, such as a button touch or click.
Whether the android:state_focused has the focus, such as when a user selects a text box.
Android:state_hovered the cursor is hovering, usually the same as focused state, which is a new feature of 4.0
Android:state_selected is selected, and it is not exactly the same as the focus state, when a list view is selected, the various sub-components within it may be selected by the arrow keys.
Whether the Android:state_checkable component can be check. For example: RadioButton can be check.
Android:state_checked was checked, such as: A RadioButton can be check.
Android:state_enabled can accept touch or click events
Android:state_activated is activated (this trouble for example, not special)
Android:state_window_focused whether the application is in the foreground, when a notification bar is pulled down or a dialog box pops up, the application is not in the foreground.
Note: If you have more than one item, the program will automatically match from top to bottom, and the first match will be applied. (not through Best Bets)
If an item does not have any status descriptions, it will be able to be matched by any one of the states.
Please see the official API, which is written in more detail! Http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
from:http://blog.csdn.net/leasystu/article/details/7250885
"Go" Android drawable State individual properties