selector (SELECT)
When we are on a control, we want to trigger a different background for different events. For example: We need to be a button, the normal state is a picture, click Down, and then change into another image.
Steps:
1: To a drawable file under the Res folder, and then create an XML file. Define the state you need to remember in the inside and refer to the corresponding picture
2. Used in the control, generally use android:background= "@drawable/dd" (here dd is the file name of our custom XML file)
Such a way
For example DD file contents are as follows:
<?XML version= "1.0" encoding= "Utf-8"?><selectorxmlns:android= "Http://schemas.android.com/apk/res/android"> <!--background color When the control is not clicked - <Itemandroid:state_pressed= "false"android:drawable= "@color/coloraccent"></Item> <!--background color when the control is clicked - <Itemandroid:state_pressed= "true"android:drawable= "@color/colorprimarydark"></Item></selector>
Control Reference Method:
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"> <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "200px" android:background= "@drawable/dd" android:clickable= "true" /> ;//must be given an initial state of the control</LinearLayout>
Android Selector Select