【问题标题】:Button color is not changed.Android Studio按钮颜色没有改变。Android Studio
【发布时间】:2021-03-29 23:53:10
【问题描述】:

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

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

【问题讨论】:

标签: android android-studio button colors


【解决方案1】:

创建一个样式以消除 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" />

【讨论】:

    猜你喜欢
    • 2021-10-04
    • 1970-01-01
    • 2015-10-29
    • 2021-07-02
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 2016-11-13
    相关资源
    最近更新 更多