AndroidStudio无法改变Button背景颜色解决办法

使用版本:android studio-hedgehog(2023年的刺猬版)

问题描述:由图观测到Button设置的是#cccccc(灰色),但按钮仍然为紫色

问题原因:此版本默认使用的主题,覆盖了Button的背景色设置

解决办法:在工程里找到themes.xml文件打开(工程→项目→res→values→themes.xml)

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Base.Theme.MyApplication" parent="Theme.Material3.DayNight.NoActionBar">
        <!-- Customize your light theme here. -->
        <!-- <item name="colorPrimary">@color/my_light_primary</item> -->
    </style>

    <style name="Theme.MyApplication" parent="Base.Theme.MyApplication" />
</resources>

把其中

<style name="Base.Theme.MyApplication" parent="Theme.Material3.DayNight.NoActionBar">

parent后面的值改为Theme.MaterialComponents.DayNight.NoActionBar.Bridge

<style name="Base.Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge">

注意,是替换文本,按照网络上很多解决办法说的直接在末尾加.Bridge会报error:

Cannot resolve symbol 'Theme.Material3.DayNight.NoActionBar.Bridge'

  • 17
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值