1.selector from the meaning of the word: The selector is the control of your goal. Selector is primarily used in the ListView item click Style and TextView and button's click Style.
2. The main attributes are:
Android:state_selected selected
Android:state_focused Get Focus
android:state_pressed Click
Android:state_enabled setting whether to respond to an event, refers to all events
3. Here's an example of selector setting for TextView:
1). Create a drawable folder under Res to install textselector.xml, place the definition of the click Style
2). Load the Textselector.xml resource on the TextView
Textselector.xml
<?XML version= "1.0" encoding= "Utf-8"?><selectorxmlns:android= "Http://schemas.android.com/apk/res/android"> <ItemAndroid:color= "#45c01a"android:state_pressed= "true"/> <ItemAndroid:color= "#9a9a9a"/></selector>
Activity_main.xml
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent" > <TextViewAndroid:id= "@+id/textview"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_centerhorizontal= "true"Android:paddingbottom= "4DP"Android:text= "Home"Android:textcolor= "@drawable/textselector"android:textsize= "20SP" > </TextView></LinearLayout>
However, after running the program click TextView will not see TextView color changes, this is because the TextView has not been added to listen to the event, even if the event does not take what function must be set.
TextView TextView = (TextView) Findviewbyid (R.id.textview); Textview.setonclicklistener (null);
Android TextView selector click Style change)