Android selector usage instructions
1. Create an xml file at drawable/xxx. xml. Remember to put the relevant images in the same directory.
Android: drawable = "@ drawable/pic1"/>
Android: state_pressed = "true" Android: drawable = "@ drawable/pic2"/>
Android: state_pressed = "true" Android: drawable = "@ drawable/pic3"/>
Android: drawable = "@ drawable/pic4"/>
Android: drawable = "@ drawable/pic5"/>
Ii. Use an xml file:
1. Method 1: Configure android: listSelector = "@ drawable/xxx in listview
Alternatively, you can add the property android: background = "@ drawable/xxx" to the listview item"
2. Method 2: Drawable drawable = getResources (). getDrawable (R. drawable. xxx );
ListView. setSelector (drawable); however, when the list is sometimes black, you must add android: cacheColorHint = "@ android: color/transparent" to make it transparent.
Related attributes:
Android: state_selected is selected
Android: state_focused is the focal point
Android: state_pressed: Click
Android: state_enabled is used to set whether to respond to events. It refers to all events.
You can also set the selector effect of the button Based on these statuses. You can also set selector to change the text status in the button.
Configure the text effect in the button:
Drawable/button_font.xml
Button can also achieve more complex effects, such as gradient
Drawable/button_color.xml
/
// Define the form when the button is in the pressed state.
Android: startColor = "# 8600ff"/>
Android: width = "2dp" android: color = "#000000"/>
Android: bottom = "10dp" android: right = "10dp"/>
// Define the form when the button obtains the focus
Color = "# ffffff"/>
Android: bottom = "10dp" android: right = "10dp"/>
Finally, you need to add two items to the xml file containing the button. For example, in the main. xml file Add two android: focusable = "true"Android: background = "@ drawable/button_color"