首页 > 解决方案 > 按钮颜色没有改变。Android Studio

问题描述

每次我想通过 xml 更改按钮的颜色时,颜色都不会改变并保持默认颜色。当我通过java代码改变颜色时,颜色会改变,但完全变成另一种我不想要的颜色。现在我通过更改themes.xml 文件中的默认颜色来更改按钮的颜色。

我在 Youtube 上尝试了很多方法,在 stackoverflow 上搜索了旧答案,但无法解决问题。如何在我的 Android Studio 中解决这个问题?

标签: androidandroid-studiobuttoncolors

解决方案


创建一个样式来消除Tinte,把backgroundTint@null和一切都应该工作。

这是我添加的样式

 <style name="NotTintedButton" parent="Widget.AppCompat.Button.Colored">
        <item name="backgroundTint">@null</item>
 </style>

你所要做的就是在你的按钮上应用这种风格。例如 :

 <Button        
        style="@style/NotTintedButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/primary_dark"
        android:textSize="22sp" />

推荐阅读