Material-components-android: [MaterialButton] Can't set background color for it

Created on 25 Oct 2019  ·  5Comments  ·  Source: material-components/material-components-android

Description: Normally, we initialize a button background by android:background="@color/dark_orange", however, in my case, it can not change the color into orange, it always be white color.

Expected behavior: The button color should be orange, but it always be white. Also, i print it value of color like this: Log.e(TIMEORY_GLOBAL_TAG, "The color is:${goTravelBtn.background}"), and the log result is:

2019-10-25 11:32:04.946 11308-11308/com.xxx.timeory E/Timeory GLOBAL_LOG: The color is:android.graphics.drawable.RippleDrawable@bdad964

Source code:

<com.google.android.material.button.MaterialButton
        android:id="@+id/goTravel"
        android:layout_width="280dp"
        android:layout_height="54dp"
        android:layout_marginBottom="36dp"
        android:background="@color/dark_orange"
        android:gravity="center"
        android:textSize="@dimen/text_size_normal"
        android:text="Go travelling"
        android:textColor="@color/white"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

Android API version: 29

Material Library version: 1.2.0-alpha-01

Device: Pixel 2 API 29

To help us triage faster, please check to make sure you are using the latest version of the library.

We also happily accept pull requests.

bug

Most helpful comment

@MGaetan89 That's right. I will use AppCompatButton instead, this widget is not effected by Materials :)

All 5 comments

Oh, MaterialButton just designed like this, okey.

Did you try the app:backgroundTint attribute instead?

@MGaetan89 Yeah, but it can't support drawable resource type when i wana a selector.

Indeed, it's only for color, but that's what you asked for in your original question :)

@MGaetan89 That's right. I will use AppCompatButton instead, this widget is not effected by Materials :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ataulm picture ataulm  ·  3Comments

sepehr-alipour picture sepehr-alipour  ·  3Comments

gabrielemariotti picture gabrielemariotti  ·  3Comments

jaychang0917 picture jaychang0917  ·  3Comments

JavierSegoviaCordoba picture JavierSegoviaCordoba  ·  3Comments