I find out that since Android Studio 4.1 I cannot change the background color of a Button
by setting color on its android:background
, just no effect. And custom Drawable
is not working as well.
My background Drawable
:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1.5dp"
android:color="@android:color/black" />
<solid
android:color="@android:color/white" />
<corners
android:radius="8dp" />
</shape>
My Button
:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add To Cart"
android:background="@drawable/background3"/>
Result:
Theme.MaterialComponents
? If so, that seems to be the source of the problem, based on some light testing. Try switching to aTheme.AppCompat
-based theme. – Appellationandroid:background
. What disappoints me is that they made it the default in the Android Studio new-project wizard for some (all?) templates. – Appellation