0

Why are my button colors not changing?

<application android:label="Sales Plus" android:icon="@drawable/Icon" 
 android:theme="@style/AppTheme"></application>

Where App Theme is defined as:

<style name="AppTheme.Base" parent="Theme.AppCompat.Light">


</style>
  <!-- inherit from the AppCompat theme -->
  <style name="AppTheme" parent="AppTheme.Base">
    <!-- Color overrides -->
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
    <!-- Background Color Override -->
    <item name="android:windowBackground">@color/window_background</item>
  </style>

A theme is created

<style name="ButtonTheme" parent="Widget.AppCompat.Button">
    <item name="colorButtonNormal">@color/primary</item>
    <item name="colorControlHighlight">@color/accent</item>
  </style>

Styling for ButtonSM:

<style name="ButtonSm" parent="Widget.AppCompat.Button.Colored">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
</style>

Theme is applied:

<Button
      android:text="@string/about"
      android:id="@+id/btnAbout"
      style="@style/ButtonSm"
      android:theme="@style/ButtonTheme"
      />

However, the button color that appears is the default green. Using Xamarin.Android.Support.v7.AppCompat and Android Framework version 7.1 (API lvl 25). Also, tested on Lollipop...

I've tried changing the ButtonTheme parent to ThemeOverlay as well as Widget.AppCompat.Button.Colored

I've already looked into Coloring Buttons in Android with Material Design and AppCompat

mgabz
  • 673
  • 1
  • 9
  • 17

1 Answers1

0

There were styles being applied to another element in the axml that didn't actually exist. After removing them, the styles were applied without issue.

I declared my primary and accent colors in the App Theme(values v-21), which was applied in manifest.xml. The AppCompat theme automatically applied the accent color to my buttons throughout the application.

I hope this post is helpful to others.

mgabz
  • 673
  • 1
  • 9
  • 17