When defining a drawable, we can use the drawable object defined in xml. It enables an image to display different patterns in different States. For example, a Button has the options of pressed, focused, or other States. By using the state list drawable, you can provide different images for each status.
Let's first look at an example:
This layout XML applies the state list drawable to a Button:
Android: drawable: place a drawable Resource
Android: whether to press state_pressed, such as a button to touch or click.
Android: state_focused indicates whether to obtain the focus. For example, you have selected a text box.
Android: state_hovered: whether to hover the cursor. It is usually the same as the focused state. It is a new feature of 4.0.
Android: state_selected is selected. It is not exactly the same as the focus state. When a list view is selected, its child components may be selected through the direction keys.
Android: whether the state_checkable component can be checked. For example, RadioButton can be checked.
Android: state_checked has been checked. For example, a RadioButton can be checked.
Android: state_enabled can accept touch or click events
Android: state_activated is activated (this is not a special example)
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 there are multiple items, the program will automatically match from top to bottom, and the first matching will be applied. (Not through the best match)
If an item does not have any state description, it can be matched by any State.
For more information, see the official API ~! Http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList