2

I have trouble in changing the background color and text color of my buttons in my app.

I made a new theme to play around and try it out. My manifest looks like this:

<application
    ...
    android:theme="@style/OrangeWhite">
    <activity android:name=".MainActivity">
    ...
</application>

My theme.xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="OrangeWhite" parent="android:Theme.Light">
        <item name="android:windowBackground">@color/OrangeWhite_bg_color</item>
        <item name="android:textColor">@color/OrangeWhite_wh_text</item>
        <item name="android:colorButtonNormal">@color/OrangeWhite_bg_btn</item>
    </style>

</resources>

Changing text or background color of an activity works just fine. The problem is the button. Do I need to specify on every button to use the theme OrangeWhite?...

mulla
  • 143
  • 1
  • 11
  • Create another theme and use it – Vinothkumar Nataraj Jul 26 '16 at 10:56
  • 1
    Maybe duplicate question, see [this](http://stackoverflow.com/questions/2410836/how-do-i-apply-a-style-to-all-buttons-of-an-android-application) – FarshidABZ Jul 26 '16 at 10:56
  • @FarshidABZ I did as it said on the link but then the parent diden't seem to work as it should since by changing the background of the button also changed size, bold and other stuff somehow. Even tho I had android:Theme.Light as parent just as before. –  Jul 26 '16 at 13:39

1 Answers1

4

If you are using AppCompat theme as parent than try below code

If you need to change the style of a specific button, you can define a new style, inheriting one of the parent styles described above. In the example below I just changed the background and font colors:

<style name="AppTheme.Button" parent="Widget.AppCompat.Button.Colored">
<item name="colorButtonNormal">@color/Red</item>
<item name="android:colorButtonNormal">@color/Red</item>
<item name="android:textColor">@color/White</item>
</style>

Then you just need to apply this new style on the button with:

android:theme="@style/AppTheme.Button"
Shrenik Shah
  • 1,900
  • 1
  • 11
  • 19