从 Android Studio 4.1 开始,Android 背景可绘制对象在按钮中不起作用 [英] Android Background Drawable Not Working in Button Since Android Studio 4.1

查看:35
本文介绍了从 Android Studio 4.1 开始,Android 背景可绘制对象在按钮中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现从 Android Studio 4.1 开始,我无法通过在 android:background 上设置颜色来更改 Button 的背景颜色,只是没有效果.自定义 Drawable 也不能正常工作.

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.

我的背景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>

我的按钮:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Add To Cart"
    android:background="@drawable/background3"/>

结果:

推荐答案

Android Studio 4.1 新项目向导,对于它的许多模板,项目都使用 Material Components for Android 库.并且,它将默认主题设置为基于 Theme.MaterialComponents.DayNight.DarkActionBar.

The Android Studio 4.1 new-project wizard, for many of its templates, has the project use the Material Components for Android library. And, it sets up the default theme to be based on Theme.MaterialComponents.DayNight.DarkActionBar.

这样做的副作用是布局中的任何

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆