How to Use color selector to report errors

Source: Internet
Author: User

Currently, most color selector methods on the Internet are as follows:

<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_selected="true" android:color="#FFF" />    <item android:state_focused="true" android:color="#FFF" />    <item android:state_pressed="true" android:color="#FFF" />    <item android:color="#000" /></selector></span>

However, in some use cases, an error is reported, indicating that the drawable is not correct. After careful research, you can actually make the color into a drawable form before using it, in this way, you can directly use drawable selector. First, we define the color as drawable in the color file.

<span style="font-size:14px;"><drawable name="menu_bg_normal">#00000000</drawable><drawable name="menu_bg_pressed">#50000000</drawable></span>
Then define the drawable selector.

<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/stu_menu_bg_pressed"/>    <item android:drawable="@drawable/stu_menu_bg_normal"/></selector></span>

Bingo! So that you don't have to worry about the color selector problem !!

How to Use color selector to report errors

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.