Detailed example of Android selector
Detailed explanation of Android selector
preface:
Statelistdrawable is a drawable defined through XML files. It uses several different pictures to present the same graph, and switches through the state of the object. For example, a button has several different states (pressing, obtaining focus, etc.). In this case, you can use different background pictures in different states by using state list drawable.
You can describe the state list in an XML file. Add each graph by defining an item element under the root node selector. Different status attributes are used in each item to define different drawable.
Each time the state changes, the state list will be traversed from top to bottom, and the first item matching the current state will be used - this selection is not to make the "best match" result, but simply find the first matching state@ H_ 404_ 13@
Generally, the selector is used as the background of the view with state changes, so that when the user operates the view and causes the view state to change, the user can make changes, so that the user can perceive the view state changes.
Official description
File location: RES / drawable / filename.xml
Compile resource type: statelistdrawable
Resource reference: @ h_ 404_ 13@
In Java: R.drawable.filename @H_ 404_ 13@ In XML: @[package:]drawable/filename
Syntax:
For more details, please refer to xsoftlab
Actual use
The following is a simple example to process the background of the button according to the status
XML file
selector_ ts.xml
Main layout file (activity_main. XML)
The code part is relatively simple, so it doesn't take up too much space here. Look at the simple effect, and you should know how to write a small activity.
Actual effect
If you have any questions, please leave a message or go to the community of this site for communication and discussion. There are many articles on Android Development on this site. Welcome to search and consult. Thank you for reading. I hope it can help you. Thank you for your support to this site!