Android--selector Simple to use

Source: Internet
Author: User

Selector---Selector

Selector can often be seen in the use of the app

Such as: A key appears white or other color, may be a picture

Press down and show other colors or another picture

Use shape together here

Normal state

<?xml version= "1.0" encoding= "Utf-8"?><!--Rectangle rectangular Oval oval line one wire ring  ring--><shape    Android:shape= "Rectangle"    xmlns:android= "http://schemas.android.com/apk/res/android" >    <!-- 4 corners of rounded corners--    <corners android:radius= "8DP"/>    <!--inner margin-    <padding android:bottom= "5DP"        android:left= "3DP"        android:right= "3DP"        android:top= "5DP"/>    <!--fill Color-    < Solid android:color= "#09A3DC"/>    <!--border Color-    <stroke android:color= "#88000000"        Android : width= "1DP"/>    </shape>

Press the status

<?xml version= "1.0" encoding= "Utf-8"?><!--Rectangle rectangular Oval oval line one wire ring  ring--><shape    Android:shape= "Rectangle"    xmlns:android= "http://schemas.android.com/apk/res/android" >    <!-- 4 corners of rounded corners--    <corners android:radius= "8DP"/>    <!--inner margin-    <padding android:bottom= "5DP"        android:left= "3DP"        android:right= "3DP"        android:top= "5DP"/>    <!--fill Color-    < Solid android:color= "#0066A0"/>    <!--border Color-    <stroke android:color= "#88000000"        Android : width= "1DP"/>    </shape>

Selector

<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android >    <!--Press to display this shape    android:state_pressed= "True" here can have a variety of state options,--    <item android:drawable= "@drawable/shap_btn_press" android:state_pressed= "true"/>    <!--usually show this shape-->    <item android:drawable= "@drawable/shap_btn_normal"/></selector>

References in layouts

<button        android:layout_margin= "10DP"        android:layout_width= "match_parent"        android:layout_height = "Wrap_content"        android:textcolor= "#ffffff"        android:background= "@drawable/selector_main_btn"         android:text= "OK"/>

There are pictures to go to need to create a selector in drawable specify a different picture, in ImageView specify background use selector, and then specify the phase event to trigger,

Here is the Click event

<selector xmlns:android= "Http://schemas.android.com/apk/res/android" >    <item android:state_pressed= " True "android:drawable=" @drawable/ic_menu_add_pressed "/>    <item android:drawable=" @drawable/ic_menu_add _normal "/></selector>

Android--selector Simple to use

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.