The selector method is used to make the listview, the item background of the gridview color change, and the selectorgridview
For more information, see http://blog.csdn.net/harryweasley/article/details/44955845. thank you.
After I click an item, the background of the item will change continuously,
When I first started using state_selected, I thought about clicking the item. After the item is selected, his background will change, but it didn't work,
Then google found a way to achieve this effect,
We should use state_activated instead of state_selected, and set its property android: choiceMode = "singleChoice" to listview or gridview in xml"
Ensure that only one item is selected
The files in selector are as follows:
<? Xml version = "1.0" encoding = "UTF-8"?> <Selector xmlns: android = "http://schemas.android.com/apk/res/android"> <! -- Background after pressing --> <item android: drawable = "@ drawable/poupwindow" android: state_pressed = "true"> </item> <! -- Background after selection --> <item android: drawable = "@ drawable/poupwindow" android: state_activated = "true"> </item> <! -- Default background --> <item android: drawable = "@ drawable/gridview_item"> </item> </selector>
For more information about selector, click here for usage of Selector in Android
Reference: http://stackoverflow.com/questions/15767274/state-selected-is-not-working-although-state-pressed-works