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:
- <Drawable name = "color_red"> # fffa3d39 </drawable>
- <Drawable name = "color_green"> # ff00adba </drawable>
- <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.
- <? 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 step 2 to the textColor option in your layout file.
Success!