Material-components-android: MaterialButton backgroundTint ignored on API level 19

Created on 25 Jun 2018  路  5Comments  路  Source: material-components/material-components-android

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

Most helpful comment

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.

All 5 comments

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.

Just retested with:

    api 'com.google.android.material:material:1.0.0'

released on Sep 22 and the issue is still present.

Closing this issue out to consolidate communication to one channel.

Please continue the discussion on https://issuetracker.google.com/issues/116862452

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"

Was this page helpful?
0 / 5 - 0 ratings