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