The buttons usually have two pre-and post-click statuses, such as blue before clicking, gray after clicking, and no longer responding to click events.
If you do not use the selector selector, you will need to do the following similar actions in the program when you click
Button1.setbackgroundresource (r.color.material_grey_300); Button1.settextcolor (Getresources (). GetColor ( R.COLOR.MATERIAL_GREY_50)); Button1.setclickable (false);
If you use the selector selector, we can simplify the above operation to
Button1.setenabled (false);
The selector code is as follows:
<selectorxmlns:android= "Http://schemas.android.com/apk/res/android"><ItemAndroid:color= "@color/igame_normal_white_color"android:state_pressed= "true" /><ItemAndroid:color= "@color/igame_actionbar_button_pressed_color"android:state_enabled= "false" /><ItemAndroid:color= "@color/igame_normal_op_color" /></selector>
The specific use is as follows:
Create a new XML file, such as Button_color_selector.xml, and then put the code for the selector block into the file.
In the layout file, set the button's Properties in the Button tab
android:background= "@drawable/button_color_selector"
Using the selector selector simplifies the code and can be reused, setting its properties directly when other components need to be used.
Use of the Android selector selector