How to change android button text color globally i

2019-04-03 08:18发布

How can I change all my buttons text color?

I know I can set the background color like follows :

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    ...
    <item name="colorButtonNormal">@color/buttonColor</item>
</style>

How can I do this for the button Text?

4条回答
对你真心纯属浪费
2楼-- · 2019-04-03 08:46

For anyone that stumbles onto this, I recommend checking out a similar question about Material Design Button Styles. With a theme, your "accent color" will be used to color your button.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    ...
    <item name="android:buttonStyle">@style/Widget.AppCompat.Button.Colored</item>
    <item name="buttonStyle">@style/Widget.AppCompat.Button.Colored</item>
</style>
查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-04-03 08:48
 <style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
   <item name="android:textColor">#yourcolor</item>
    <item name="android:buttonStyle">@style/ButtonColor</item>
    <item name="colorButtonNormal">@color/buttonColor</item>
</style>



<style name="ButtonColor" parent="@android:style/Widget.Button">
   <item name="android:textColor">@color/yourcolor</item>
</style> 

android:textColor This should help you change the text color globally. I hope this is helpful ThankYou

查看更多
你好瞎i
4楼-- · 2019-04-03 08:56

If you just need to change the text colour of buttons. You can modify the textAppearanceButton style attribute of your main theme.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorButtonNormal">@color/buttonColor</item>
    <item name="android:textAppearanceButton">@style/TextAppearance.AppCompat.Button.Custom</item>
</style>

And declare your new textAppearance style as follows

<style name="TextAppearance.AppCompat.Button.Custom">
    <item name="android:textColor">@color/mycustomcolor</item>
</style>
查看更多
我想做一个坏孩纸
5楼-- · 2019-04-03 09:00

Just using AppCompatButton by setting this attribute :

"app:backgroundTint="@color/wildberries"

And make sure your activity extends AppCompatActivity. I just use it in my project. It works like a charm in both 5.X and pre-5.X.

查看更多
登录 后发表回答