In Android, the font color changes after a button is clicked. androidbutton

Source: Internet
Author: User

In Android, the font color changes after a button is clicked. androidbutton

The button clicking effect is undoubtedly very simple, I was so lazy that when the UI told me that the color of the button font would change with the background when I clicked, I did not hesitate to tell him to cut two pictures, later I thought it was not very reliable, so I learned how to add the font color change effect of button clicks.

1. First, you need to add a few required color values under your color file. Note that the difference is not a general color tag, but a drawable tag, just like this:

    1. <Drawable name = "color_red"> # fffa3d39 </drawable>
    2. <Drawable name = "color_green"> # ff00adba </drawable>
    3. <Drawable name = "color_gray"> # fff4f4f8 </drawable>

2. Then you need to define a drawable file, which is similar to the normal selector file. The only difference is that the drawable field is changed to color and the color you just defined is introduced in it, just like this.

    1. <? Xml version = "1.0" encoding = "UTF-8"?>
    2. <Selector xmlns: android = "http://schemas.android.com/apk/res/android">
    3. <Item android: state_focused = "false" android: state_enabled = "true" android: state_pressed = "false"
    4. Android: color = "@ drawable/color_red"/>
    5. <Item android: state_enabled = "false" android: color = "@ drawable/color_gray"/>
    6. <Item android: state_pressed = "true" android: color = "@ drawable/color_green"/>
    7. <Item android: state_focused = "true" android: color = "@ drawable/color_red"/>
    8. </Selector>

3. Finally, set the drawable file written in step 2 to the textColor option in your layout file.

Success!

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.