3.APP resources-resource Types/color State List Resource

Source: Internet
Author: User

1. Color State List Resource

A colorstatelist is an object you can define in XML so can apply as a color, but would actually change Colors, depending on the State of

The View object to which it is applied. For example, a Button widget can exist in one of several different states (pressed, focused, or

niether) and, using a color state list, you can provide a different the color during each state.

You can describe the "state" list in an XML file. Each color was defined <item> in an element inside <selector> a single element. Each <item> uses

Various attributes to describe, the state of which it should be used.

2. Syntax

<?xml version="1.0"encoding="Utf-8"? ><selector xmlns:android="http://schemas.android.com/apk/res/android">//This must is the root element. Contains one or more <item> elements. <item//defines a color to use during certain States, as described by its attributesAndroid:color="Hex_color"android:state_pressed=["true"|"false"] android:state_focused=["true"|"false"] android:state_selected=["true"|"false"] Android:state_checkable=["true"|"false"] android:state_checked=["true"|"false"] android:state_enabled=["true"|"false"] android:state_window_focused=["true"|"false"]/></selector>

3. Example

//Res/color/button_color.xml<?xml version="1.0"encoding="Utf-8"? ><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"Android:color="#ffff0000"/> <!--pressed-<item android:state_focused="true"Android:color="#ff0000ff"/> <!--focused-<item android:color="#ff000000"/> <!--default--></selector>
// activity.xml<button        android:layout_width="wrap_content"         android:layout_height="wrap_content"        Android:textcolor ="@color/button_color"        android:text="  Button" />

3.APP resources-resource Types/color State List Resource

Related Article

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.