31

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?

Gabriele Mariotti
  • 250,295
  • 77
  • 670
  • 690
Zapnologica
  • 21,164
  • 41
  • 147
  • 239
  • 1
    [Check this](http://stackoverflow.com/questions/14023601/android-style-specify-button-color) – M D Mar 28 '16 at 11:31

6 Answers6

49
 <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.

thepurpleowl
  • 137
  • 4
  • 15
Sumanth Jois
  • 3,054
  • 2
  • 25
  • 38
14

With the new Theme.MaterialComponents theme you can define the materialButtonStyle attribute in your app theme.

  <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light">
    ....

    <item name="materialButtonStyle">@style/MyButtonTheme</item>
  </style>

In this way you can customize globally the style of all buttons in your app. You can override the theme attributes from the default style using the materialThemeOverlay attribute.

Something like:

  <style name="MyButtonTheme" parent="Widget.MaterialComponents.Button">
    <item name="materialThemeOverlay">@style/ButtonStyleTextColor</item>
  </style>

  <style name="ButtonStyleTextColor">
    <!-- For filled buttons, your theme's colorPrimary provides the default background color of the component, and -->
    <!--the text color is colorOnPrimary -->
    <item name="colorPrimary">@color/my_color</item>
    <item name="colorOnPrimary">@color/my_color2</item>

  </style>

Currently the materialThemeOverlay attribute requires version 1.1.0 of material components for android library.

Gabriele Mariotti
  • 250,295
  • 77
  • 670
  • 690
11

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>
dishan
  • 1,306
  • 12
  • 21
11

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>
Community
  • 1
  • 1
sschmitz
  • 412
  • 7
  • 15
0

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.

-3
<Button  
     app:backgroundTint="#fece2f" //any color
 />

This is best way if you don't want it to be defined globally

Omkar Ghurye
  • 140
  • 1
  • 8