Click to change the implementation of the image, click to change the implementation of the image
<? Xml version = "1.0" encoding = "UTF-8"?> <Selector xmlns: android = "http://schemas.android.com/apk/res/android"> <! -- The following is the android namespace --> <item android: state_focused = "true" android: state_enabled = "true" android: state_pressed = "false" android: drawable = "@ drawable/compass"/> <! -- Set the image that is not displayed when it is not pressed --> <item android: state_enabled = "true" android: state_pressed = "true" android: drawable = "@ drawable/center_bg_click"/> <! -- The image displayed when you press --> <item android: state_enabled = "true" android: state_checked = "true" android: drawable = "@ drawable/center_bg_click"/> <item android: drawable = "@ drawable/compass"/> </selector>
Usage:
1. Create a drawable folder under the res Resource Directory
2. Create an android xml file, input the above Code, and replace the corresponding image reference.
3. After the image is created, use the image as usual @ drawable/xxxx. xml (in the xml layout) or R. drawable. xxx in the program segment.
4. The reason in 3 is that after the file is created successfully. the drawable class of a java file generates a member variable referenced by the xml file name. The usage is the same as that of a common image.