Android deep analysis selector

Source: Internet
Author: User

Android deep analysis selector
The selector class is similar to the shape class, which is used to set the properties of the control in an xml file and then reference it. The basic attributes of selector are as follows:

Android: drawable = "@ drawable/pic2"/>

Android: drawable = "@ drawable/pic3"/>

You can use the following methods:

First, configure android: listSelector = "@ drawable/list_item_bg" in listview"

You can also add the property android: background = "@ drawable/list_item_bg" to the listview item.

Or use the following in java code:

Drawable drawable = getResources (). getDrawable (R. drawable. list_item_bg );

ListView. setSelector (drawable); same effect.

However, when the list is sometimes black, you need to add android: cacheColorHint = "@ android: color/transparent" to make it transparent.

Some background Effects of the Button:

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 use selector and shape nesting:

Android: bottom = "10dp" android: right = "10dp"/>

Android: bottom = "10dp" android: right = "10dp"/>




Below is:
If you have any questions, please leave a message. If you have reprinted the message, you can indicate the source.

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.