The selector method is used to make the listview, the item background of the gridview color change, and the selectorgridview

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.