Selector define different realistic effects based on different selected states
Common Properties:
Android:state_selected--------Selected
android:state_focused--------Get Focus
android:state_pressed--------Click
android:state_enabled--------setting whether to respond to events
============================
Android:drawable put a drawable resource
Whether the android:state_pressed is pressed, such as a button touch or click.
Whether the android:state_focused has the focus, such as when a user selects a text box.
Android:state_hovered the cursor is hovering, usually the same as focused state, which is a new feature of 4.0
Android:state_selected is selected, and it is not exactly the same as the focus state, when a list view is selected, the various sub-components within it may be selected by the arrow keys.
Whether the Android:state_checkable component can be check. For example: RadioButton can be check.
Android:state_checked was checked, such as: A RadioButton can be check.
Android:state_enabled can accept touch or click events
Android:state_activated is activated (this trouble for example, not special)
Android:state_window_focused whether the application is in the foreground, when a notification bar is pulled down or a dialog box pops up, the application is not in the foreground.
Some need to add android:focusable and android:clickable to be true to get focus
Simple example: Click the button to change the style
Button:
<button android:layout_width= "160DP" android:layout_height= "wrap_content" android:background= "@ Drawable/button_select " android:text=" point I Color " />
Button_select.xml
<selector xmlns:android= "Http://schemas.android.com/apk/res/android" > <item android:state_pressed= " True "android:drawable=" @drawable/play_button "></item> <item android:state_focused=" true "Android :d rawable= "@drawable/play_button" ></item> <item android:drawable= "@drawable/button" ></ Item></selector>
Button.xml Default Effect
<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <solid android:color= "#E53B36"/></shape>
Play_button.xml Click Effect
<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <solid android:color= "#E8B714"/></shape>
Common checkbox Settings:
<?xml version= "1.0" encoding= "UTF-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:state_window_focused=" false "android:state_enabled=" true "android:state_checked=" True "android:drawable=" @drawable/btn_check_on "/> <item android:state_window_focused=" false "Android:state_ Enabled= "true" android:state_checked= "false" android:drawable= "@drawable/btn_check_off"/> <item android: State_enabled= "true" android:state_checked= "true" android:state_pressed= "true" android:drawable= "@drawable/btn_ Check_on_pressed "/> <item android:state_enabled=" true "android:state_checked=" false "android:state_pressed=" True "android:drawable=" @drawable/btn_check_off_pressed "/> <item android:state_focused=" true "Android:state_ Enabled= "true" android:state_checked= "true" android:drawable= "@drawable/btn_check_on_selected"/> <item Android:state_focused= "true" android:state_enabled= "true" android:state_checked= "false" android:drawable= "@drawable/btn_check_off_selected"/> <item android:state_enabled= "true" Android:state_ Checked= "false" android:drawable= "@drawable/btn_check_off"/> <item android:state_enabled= "true" Android: State_checked= "true" android:drawable= "@drawable/btn_check_on"/></selector>
Common ImageButton settings:
<?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/button2_down "/> < Item android:state_focused= "True" android:state_enabled= "true" android:drawable= "@drawable/button2_over"/> <item android:state_enabled= "true" android:drawable= "@drawable/button2"/></selector>
Common button settings:
<?xml version= "1.0" encoding= "UTF-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:state_enabled=" false "android:drawable=" @drawable/login_input "/> < Item android:state_pressed= "True" android:drawable= "@drawable/login_input"/> <item Android:state_ Focused= "true" android:drawable= "@drawable/input_over"/></selector>
Set TextView
<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:color=" @color/gray "android:state_pressed=" false "android:state_enabled=" true "/ > <item android:color= "@color/white" android:state_pressed= "true" android:state_enabled= "true"/> <item android:color= "@color/gray" android:state_enabled= "false"/></selector>
Android:res's selector background selector