android按钮背景设置为蓝色,关于Android中Button的Backgroud背景设置默认为蓝紫色,且无法修改的问题...

问题简述:

在修改Button的背景颜色时,始终无法修改颜色为设置的颜色,且颜色始终为默认的蓝紫色。

android:id="@+id/btn_1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="@string/btn_1"

android:backgroundTint="@null"

android:textSize="20sp"

android:textColor="#FFFFFF"

android:background="#FF0011">

android:id="@+id/btn_2"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="@string/btn_2"

android:textSize="20sp"

android:textColor="#FFFFFF"

android:backgroundTint="@null"

android:background="@drawable/bg_btn2"

android:layout_below="@id/btn_1"

android:layout_marginTop="20dp">

android:id="@+id/btn_3"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="按钮3"

android:textSize="20sp"

android:backgroundTint="@null"

android:textColor="#FF9900"

android:background="@drawable/bg_btn3"

android:layout_below="@id/btn_2"

android:layout_marginTop="20dp">

android:id="@+id/btn_4"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="按钮4"

android:textSize="20sp"

android:backgroundTint="@null"

android:textColor="#FFFFFF"

android:background="@drawable/bg_btn4"

android:layout_below="@id/btn_3"

android:layout_marginTop="20dp">

上文中drawable/bg_btn等颜色为非默认蓝紫色。

实际模拟机效果(真机效果一样)如下:

f6f2257b1aaf8473212bbf2778946cac.png

问题解决:

博主的解决方法:

默认的颜色设置来自于res/values/themes.xml与夜间模式(应该是)下的res/values-night/themes.xml

@color/purple_500

@color/purple_700

@color/white

@color/teal_200

@color/teal_700

@color/black

?attr/colorPrimaryVariant

将(或你选择的其它主题)

修改为(或其它能够实现非默认颜色的主题)

即可解决问题,修改后的效果图如下:

b79355887f50f30beffd8a170e5d5217.png

当然,经过搜索,还得到了以下解决方法,虽然没有解决我的问题,但是希望能够帮到你:

1、给按钮增加一个属性app:backgroundTint="@null"

2、点击菜单中的 “baiFile” -> “Invalidate Caches / Restart”,然后点击对du话框中的 “Invalidate and Restart”,清空 cache 并且重启。

3、更换旧版本(或许确实是版本问题)

4、将themes文件下的

问题总结:

虽然不知道原理是什么,但是在搜索问题的时候很少人遇到这种问题,且遇到问题的多半是近期提问。总结来说应该是更新问题导致的,或者说因为我选择了空白项目导致使用了默认的themes。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值