<?xml version= "1.0" encoding= "Utf-8"?> <selector xmlns:android= "http://schemas.android.com/apk/res/ Android "><item android:state_focused=" true "<!--true when you get focus in non-touch mode when the picture is displayed-->android:state_window_focused=" True "<!--true to display the picture when this activity gets the focus first; False when the picture is not displayed in the front. -->android:state_enabled= "true" <!--true to display the picture when the component is available; False to display the picture when the component is not available. -->android:state_checkable= "true" <!--true to display the picture when the checkbox is available; False to display the picture-->android when the checkbox is not available: State_checked= "true" <!--true to display the picture when the checkbox is selected, false to display the picture when the checkbox is unchecked-->android:state_selected= "true" <!--true to display the picture when selected, False for the selected picture (for example, with TAB)-->android:state_pressed= "true" <!--true when the picture is displayed when clicked False when not pressed display picture ==click--> <!--more for ListView or toggle-- >android:state_activated= "true" <!--true to display the picture when active, false when not activated picture-->android:state_active= "true" <!---- >android:state_single= "true" <!--true only one element displays the picture-->android:staTe_first= "true" <!---->android:state_middle= "true" <!---->android:state_last= "true" <!----> Android:state_accelerated= "true" <!--true for hardware acceleration to True picture-->android:state_hovered= "true" <!--true The mouse (pointer) moves to that position when the picture-->android:state_drag_hovered= "true" <!--true to drop or drag the mouse pointer to that position picture--Android:state_ Drag_can_accept= "true" <!--true to Dorp or drag when the picture-->android:state_accessibility_focused= "true" <!----> android:drawable= "@drawable/icon" <!--(general) prerequisites above photo--/> </selector>
Next, give some of the usage scenarios
<?xml version= "1.0" encoding= "Utf-8"?> <selector xmlns:android= "http://schemas.android.com/apk/res/ Android > <!--background picture by default- -<item android:drawable= "@drawable/pic1"/> < background picture when!--no focus-- > <item android:state_window_focused= "false" android:drawable= "@drawable/pic1"/> <!-- When you get the focus in non-touch mode and click the background picture-- <item android:state_focused= "true" android:state_pressed= "true" Android: drawable= "@drawable/pic2"/> <!--touch mode when clicked background picture-- <item android:state_focused= "false" Android: State_pressed= "true" android:drawable= "@drawable/pic3"/> <!--When selected picture background-- <item Android:state_selected= "true" android:drawable= "@drawable/pic4"/> <!--get focus when the picture background -- <item android:state_focused= "true" android:drawable= "@drawable/pic5"/> </selector>
Of course, we can do the same.
<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:state_selected=" true "android:color=" #FF0000 "/> <item Android:state_ Focused= "true" android:color= "#00FF00"/> <item android:state_pressed= "true" android:color= "#0000FF"/ > <item android:color= "#000000"/></selector>
Or so
<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:state_pressed=" true "> <!--defines the pattern when the button is in the pressed state. -<shape> <gradient android:startcolor= "#8600ff"/> <stroke android:width = "2DP" android:color= "#000000"/> <corners android:radius= "5dp"/> <padding android:left = "10DP" android:top= "10DP" android:bottom= "10DP" android:right= "10DP"/> </shape> </i Tem> <item android:state_focused= "true" > <!--defines the shape when the button gets focus--<shape> <gradient android:startcolor= "#eac100"/> <stroke android:width= "2DP" android:color= "#333333" Col Or= "#ffffff"/> <corners android:radius= "8dp"/> <padding android:left= "10DP" android:to p= "10DP" android:bottom= "10DP" android:right= "10DP "/> </shape> </item> <item android:drawable=" @drawable/you_picture_name "> Default background </i Tem></selector>
Here we give the key to remind selector generally used for background don't forget
android:background= "@drawable/you_drawable_xml_name"
Android Selector Full Solution