Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change android button text color globally in theme

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?

like image 240
Zapnologica Avatar asked Mar 28 '16 11:03

Zapnologica


People also ask

How do I change the color of my text buttons?

Use a semi-colon to separate the different style elements in the HTML button tag. Type color: in the quotation marks after "style=". This element is used to change the text color in the button. You can place style elements in any order in the quotation markers after "style=".

How can change background color of button in Android?

To set Android Button background color, we can assign android:backgroundTint XML attribute for Button in layout file with the required Color Value. To programmatically set or change Android Button background color, we may call pass the method Button.

How can I change the font color of my Android app name?

Search for and select Open App, and then, on the New Shortcut page, tap Choose. Locate the app whose appearance you want to change. Back on the New Shortcut page, you'll see the app name; tap More (three dots), change the app's name, tap its icon, select Color, and choose a new color.


4 Answers

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

like image 101
Sumanth Jois Avatar answered Oct 04 '22 08:10

Sumanth Jois


With the new Theme.MaterialComponents theme you can define the materialButtonStyle attribute in your app theme, to customize globally the style of all buttons in your app.

  <!-- Base application theme. -->
  <style name="AppTheme" parent="Theme.MaterialComponents.Light">
       <!-- .... --> 
       <item name="materialButtonStyle">@style/Widget.App.Button</item>
  </style>

With

<style name="Widget.App.Button" parent="Widget.Material3.Button">
    <!-- button style customization example -->
    <item name="materialThemeOverlay">@style/ThemeOverlay.App.Button</item>
    <item name="android:textAppearance">@style/TextAppearance.App.Button</item>
    <item name="shapeAppearance">@style/ShapeAppearance.App.SmallComponent</item>
</style>

Use Widget.MaterialComponents.Button as parent if you are using Material2 theme.

If you would like to override only some attributes like colors from the default style use the materialThemeOverlay attribute.

Something like:

  <style name="Widget.App.Button" parent="Widget.Material3.Button">
    <item name="materialThemeOverlay">@style/ThemeOverlay.App.Button</item>
  </style>

  <style name="ThemeOverlay.App.Button">
    <!-- 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>
like image 29
Gabriele Mariotti Avatar answered Oct 04 '22 08:10

Gabriele Mariotti


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>
like image 11
dishan Avatar answered Oct 04 '22 07:10

dishan


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>
like image 11
sschmitz Avatar answered Oct 04 '22 06:10

sschmitz