Android mobile guard-reference document to write selector, android Selector
This article implements the image selector code in "Android mobile guard-navigation interface 1 Layout writing.
For more information, see http://www.cnblogs.com/wuyudong/p/5944356.html.
This can refer to the official website provided by the API documentation picture selector written in the selection and not selected in the process of switching to display picture http://wear.techbrood.com/guide/practices/screens_support.html
Select the following entries in sequence: AppResource ---> Resource Types -----> Drawable ----> StateList
Find the relevant syntax format and sample code in the document:
Selector path res/drawable/button. xml:
<? 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"/> <! -- Select the button image --> <item android: state_focused = "true" android: drawable = "@ drawable/button_focused"/> <! -- Button to get the focus image --> <item android: state_hovered = "true" android: drawable = "@ drawable/button_focused"/> <! -- Flat panel TV, select an app Image in the floating range --> <item android: drawable = "@ drawable/button_normal"/> <! -- Default image --> </selector>
The Button above acts on the following
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="@drawable/button" />
Therefore, we can write the following code by referring to the api documentation:
Create drawable/selector_next_btn_bg.xml
<? Xml version = "1.0" encoding = "UTF-8"?> <Selector xmlns: android = "http://schemas.android.com/apk/res/android"> <! -- Select a dark green image --> <item android: state_pressed = "true" android: drawable = "@ drawable/function_greenbutton_pressed"> </item> <! -- Light green image --> <item android: drawable = "@ drawable/function_greenbutton_normal"> </item> </selector>
Add the layout code of the Button control:
<! -- Image selector: In the selection or unselected process, switch to the display image --> <Button android: text = "next page" android: background = "@ drawable/selector_next_btn_bg" android: drawableRight = "@ drawable/next" android: layout_alignParentRight = "true" android: Layout = "true" android: layout_width = "wrap_content" android: layout_height = "wrap_content"/>
The effect is as follows:
After running the project, click "next page" and the color changes.