How to set the text style of a button in selectors?

后端 未结 1 1279
暗喜
暗喜 2020-12-05 05:00

Button selectors allows to define a background for each state of the button, but how can the button\'s text style be defined for each state? My objective is to grey out a bu

相关标签:
1条回答
  • 2020-12-05 05:24

    Well!

    You can define the Text color for all 4 state, similarly as you defined background for the Button. For example:

    file name: /res/color/text_color.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_enabled="false" android:color="#440000"/>
        <item android:state_focused="true" android:color="#004400"/>
        <item android:state_pressed="true" android:color="#000044"/>
        <item android:color="#444"/> 
    </selector>
    

    Take this file into your Button Style like this:

    <style name="srp_button" parent="@android:style/Widget.Button">
        <item name="android:background">@drawable/btn_default</item>
        <item name="android:textColor">@color/text_color</item> <!-- Here is specified text color -->
    </style>
    
    0 讨论(0)
提交回复
热议问题