Android mobile guard-reference document to write selector, android Selector

Source: Internet
Author: User

Android mobile guard-reference document to write selector, android Selector

This article implements the image selector code in "Android mobile guard-navigation interface 1 Layout writing.

For more information, see http://www.cnblogs.com/wuyudong/p/5944356.html.

This can refer to the official website provided by the API documentation picture selector written in the selection and not selected in the process of switching to display picture http://wear.techbrood.com/guide/practices/screens_support.html

Select the following entries in sequence: AppResource ---> Resource Types -----> Drawable ----> StateList

Find the relevant syntax format and sample code in the document:

Selector path res/drawable/button. xml:

<? Xml version = "1.0" encoding = "UTF-8"?> <Selector xmlns: android = "http://schemas.android.com/apk/res/android"> <item android: state_pressed = "true" android: drawable = "@ drawable/button_pressed"/> <! -- Select the button image --> <item android: state_focused = "true" android: drawable = "@ drawable/button_focused"/> <! -- Button to get the focus image --> <item android: state_hovered = "true" android: drawable = "@ drawable/button_focused"/> <! -- Flat panel TV, select an app Image in the floating range --> <item android: drawable = "@ drawable/button_normal"/> <! -- Default image --> </selector>

The Button above acts on the following

    <Button        android:layout_height="wrap_content"        android:layout_width="wrap_content"        android:background="@drawable/button" />

Therefore, we can write the following code by referring to the api documentation:

Create drawable/selector_next_btn_bg.xml

<? Xml version = "1.0" encoding = "UTF-8"?> <Selector xmlns: android = "http://schemas.android.com/apk/res/android"> <! -- Select a dark green image --> <item android: state_pressed = "true" android: drawable = "@ drawable/function_greenbutton_pressed"> </item> <! -- Light green image --> <item android: drawable = "@ drawable/function_greenbutton_normal"> </item> </selector>

Add the layout code of the Button control:

<! -- Image selector: In the selection or unselected process, switch to the display image --> <Button android: text = "next page" android: background = "@ drawable/selector_next_btn_bg" android: drawableRight = "@ drawable/next" android: layout_alignParentRight = "true" android: Layout = "true" android: layout_width = "wrap_content" android: layout_height = "wrap_content"/>

The effect is as follows:

After running the project, click "next page" and the color changes.

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.