-1

I have just started learning my way around Android Studio and Android Development. I have been looking for ways to change the color of the text for all buttons in an application.

Can someone tell me the number of ways I can do this without having to hard code the color in each button using XML only?

I have used the below code which works but am looking for all possible ways to see which is easier to achieve.

<style>
...          
<!-- changes Button text colors -->
<item name="android:textAppearanceButton">@style/Base.TextAppearance.AppCompat.Button.Custom</item>
...
</style>

<style name="Base.TextAppearance.AppCompat.Button.Custom">
<item name="android:textColor">#ffffff</item>
</style>
Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
  • Possible duplicate of [Android customized button; changing text color](https://stackoverflow.com/questions/4692642/android-customized-button-changing-text-color) – reixa Jan 15 '19 at 15:30

2 Answers2

0

you can add a style for all buttons at once in your main theme

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- .... --> 
        <item name="android:button">@style/NormalBtn</item>
    </style>
0

you could easily do this from java with

Button myButton = (Button)findViewById(R.id.btn);

myButton.setTextColor(Color.ORANGE);

hope it helps

JideGuru
  • 7,102
  • 6
  • 26
  • 48