How to change android button text color globally in theme How to change android button text color globally in theme android android

How to change android button text color globally in theme


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


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>


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.