English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Color Change Effect of Button Text after Clicking in Android

The click effect of the button is undoubtedly very simple, so lazy that when the UI told me that the color of the button text should also change with the background when clicking, I told him without hesitation to let him bring two images over. Later, I thought it was actually not very reliable, so I learned how to add the effect of changing the button text color when clicking.

1.Firstly, you need to add several colors you need under your color file, note that it is not a general color tag, but a drawable tag, like this:

<drawable name="color_red">#fffa3d39</drawable> 
<drawable name="color_green">#ff00adba</drawable>/drawable> 
<drawable name="color_gray">#fff4f4f8</drawable>

2Then you need to define a drawable file, which is similar to a normal selector file, the only difference is that you change the drawable field to color where you can introduce the color you just defined, like this

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_focused="false" android:state_enabled="true" android:state_pressed="false" 
android:color="@drawable/color_red" /> 
<item android:state_enabled="false" android:color="@drawable/color_gray" /> 
<item android:state_pressed="true" android:color="@drawable/color_green" /> 
<item android:state_focused="true" android:color="@drawable/color_red" /> 
</selector>

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

The above-mentioned is the change effect of the font color after the button click in Android introduced by the editor. I hope it will be helpful to everyone!

Statement: The content of this article is from the network, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (When sending an email, please replace # with @ to report abuse, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.)

You May Also Like