Android -- selector for simple use, Android -- selector

Source: Internet
Author: User

Android -- selector for simple use, Android -- selector

Selector --- selector

Selector is often seen in App usage.

For example, if a button looks white or its hidden color, it may be an image.

Click Next to display another color or image.

 

 

 

Shape is used in combination.

Normal

<? Xml version = "1.0" encoding = "UTF-8"?> <! -- Rectangle oval line ring --> <shape android: shape = "rectangle" xmlns: android = "http://schemas.android.com/apk/res/android"> <! -- Rounded corner of the four corners --> <corners android: radius = "8dp"/> <! -- Padding --> <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 status

<? Xml version = "1.0" encoding = "UTF-8"?> <! -- Rectangle oval line ring --> <shape android: shape = "rectangle" xmlns: android = "http://schemas.android.com/apk/res/android"> <! -- Rounded corner of the four corners --> <corners android: radius = "8dp"/> <! -- Padding --> <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"> <! -- Display the shape android: state_pressed = "true" when you press it. There are multiple options for status options. --> <item android: drawable = "@ drawable/shap_btn_press" android: state_pressed = "true"/> <! -- Display the shape at ordinary times --> <item android: drawable = "@ drawable/shap_btn_normal"/> </selector>

 

Reference in Layout

<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"/>

 

If there is an image, you need to create a selector to specify different images in drawable. In ImageView, specify background to use selector, and then specify the phase event to trigger,

Below are click events

<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>

 

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.