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.
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 :)
Most helpful comment
@MGaetan89 That's right. I will use
AppCompatButtoninstead, this widget is not effected by Materials :)