Problem summary (12)-change the text color with focus

Source: Internet
Author: User

We know that the background of the button can use selector. In fact, the text also supports this feature. I tried it some time ago but did not succeed, so I gave up. I had this demand in the past two days. At first I thought I would rewrite a component, but it was not cost-effective to write a component separately for one or two buttons, so I tried my previous ideas again and succeeded. Here we will share with you:

First, we need to define our color:

[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<Color name = "white"> # ffffffff </color>
<Color name = "non" ># ff000000 </color>
<Color name = "gray"> # ff505050 </color>
</Resources>
<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<Color name = "white"> # ffffffff </color>
<Color name = "non" ># ff000000 </color>
<Color name = "gray"> # ff505050 </color>
</Resources> next, write the selector: [html] view plaincopyprint? <? Xml version = "1.0" encoding = "UTF-8"?>
<Selector xmlns: android = "http://schemas.android.com/apk/res/android">
<Item android: state_pressed = "true" android: color = "@ color/white"/>
<Item android: state_focused = "true" android: color = "@ color/white"/>
<Item android: color = "@ color/non"/> www.2cto.com
</Selector>
<? Xml version = "1.0" encoding = "UTF-8"?>
<Selector xmlns: android = "http://schemas.android.com/apk/res/android">
<Item android: state_pressed = "true" android: color = "@ color/white"/>
<Item android: state_focused = "true" android: color = "@ color/white"/>
<Item android: color = "@ color/non"/>
</Selector>

Finally, use android: textColor = "@ drawable/text" as needed"

Complete.

Author: agods
 

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.