The color effect of the font after button click in Android

Source: Internet
Author: User

The Click Effect of the button is undoubtedly very simple, so that I am lazy to when the UI tells me that the color of the button font when clicked to change with the background when I did not hesitate to tell him to cut two pictures come over, then think really is not very reliable, Then I learned how to add the font color change effect of the button click.

1. First you want to add a few of the color values you need under your color file, note that the difference is not a generic color tag, but a drawable tag, 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 want to define a drawable file, just like the normal selector file, the only difference is to turn the drawable field into color and introduce the color you just defined

    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 second step of the drawable file to the TextColor option in your layout file.

Done!

The color effect of the font after button click in Android

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.