question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MaterialButton backgroundTint ignored on API level 19

See original GitHub issue

Overview

Have a custom theme overriding Theme.MaterialComponents.Dark and custom Widget.MaterialComponents.Button style overriding button text color.

Reproduction steps

Primary Color variants are shades of dark blue. The theme editor in Android Studio displays the button preview correctly, the buttons work correctly in API level 21+ but background is completely ignored on API level 19.

In styles.xml

   <style name="AppTheme.Dark" parent="Theme.MaterialComponents">
        <item name="colorAccent">@color/colorWhite</item>
        <item name="colorControlNormal">@color/colorWhiteTranslucent88</item>
        <item name="colorControlActivated">@color/colorWhite</item>
        <item name="colorControlHighlight">@color/colorPrimaryDark</item>
   </style>

   <style name="Widget.AppComponents.Button" parent="Widget.MaterialComponents.Button">
        <item name="rippleColor">@color/colorPrimary</item>
        <item name="android:textColor">@color/colorPrimary</item>
    </style>

Operating system and device

Emulator running API level 19 and API level 21

Android Studio theme preview:

screen shot 2018-06-25 at 11 50 21

App running in emulator 21: screen shot 2018-06-25 at 11 48 32

App running in emulator 19: screen shot 2018-06-25 at 11 48 38

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
JurajKuliskacommented, Oct 23, 2018

I have just found out that if you specify rippleColor then the backgroundTint is ignored and the rippleColor is used as the background color instead.

0reactions
iRYO400commented, Jul 6, 2019

In July 2019 the issue is still not fixed, dont wanna use alpha version of Material library https://mvnrepository.com/artifact/com.google.android.material/material

So I found a workaround. Create your custom style for material buttons:

    <style name="MaterialButton" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="backgroundTint">@color/colorPrimary</item> // For API 21+
        <item name="rippleColor">@color/colorAccent</item> 
        ...
        <item name="colorAccent">@color/colorPrimary</item> // the main fix, For API 19
    </style>

then set it your MaterialButton like this android:theme="@style/MaterialButton"

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android material button set icon and background color not ...
I am using a custom style in order to change the button's background color. I have also tried directly adding the backgroundTint property...
Read more >
MaterialButton - Android Developers
A convenience class for creating a new Material button. This class supplies updated Material styles for the button in the constructor.
Read more >
Migrating to Material Components for Android
The 'Refactor> Migrate to AndroidX' tool in Android Studio will refactor your Design Support Library dependency to MDC. Note: Jetpack and MDC ...
Read more >
Visualization: Column Chart - Google Developers
For a horizontal version of this chart, see the bar chart. ... You load the Google Visualization API (although with the 'bar' package...
Read more >
Xamarin.Forms 4.6.0.1073 (4.6.0 Service Release 5) Release ...
Forms 4.6.0.847 (4.6.0 Service Release 3); Tuesday, May 19, ... with target API level 29 or 30" (#10975) (added in 4.6.0.967 (4.6.0 Service ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found