Android Selector Select

Source: Internet
Author: User

selector (SELECT)

When we are on a control, we want to trigger a different background for different events. For example: We need to be a button, the normal state is a picture, click Down, and then change into another image.

Steps:
1: To a drawable file under the Res folder, and then create an XML file. Define the state you need to remember in the inside and refer to the corresponding picture
2. Used in the control, generally use android:background= "@drawable/dd" (here dd is the file name of our custom XML file)
Such a way

For example DD file contents are as follows:

<?XML version= "1.0" encoding= "Utf-8"?><selectorxmlns:android= "Http://schemas.android.com/apk/res/android">    <!--background color When the control is not clicked -    <Itemandroid:state_pressed= "false"android:drawable= "@color/coloraccent"></Item>    <!--background color when the control is clicked -    <Itemandroid:state_pressed= "true"android:drawable= "@color/colorprimarydark"></Item></selector>

Control Reference Method:

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical">    <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "200px" android:background= "@drawable/dd"  android:clickable= "true" /> ;//must be given an initial state  of the control</LinearLayout>

Android Selector Select

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.