android - 按钮颜色没有改变。Android Studio
问题描述
每次我想通过 xml 更改按钮的颜色时,颜色都不会改变并保持默认颜色。当我通过java代码改变颜色时,颜色会改变,但完全变成另一种我不想要的颜色。现在我通过更改themes.xml 文件中的默认颜色来更改按钮的颜色。
我在 Youtube 上尝试了很多方法,在 stackoverflow 上搜索了旧答案,但无法解决问题。如何在我的 Android Studio 中解决这个问题?
解决方案
创建一个样式来消除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" />
推荐阅读
- javascript - 引导折叠事件多次触发
- r - 基于一列比较两个数据帧(具有不同长度),并检索 r 中的其他列
- tibco-ems - Tibco EMS 的独家消费者
- django - 如何通过邮递员中的cookie传递会话ID并登录?
- variables - 在 Azure Pipeline 中的作业之间传递变量
- javascript - 如何从 Javascript 或 jQuery 获取 windows 时区字符串?
- c - 有人可以解释一下 C 中以下结构的含义吗?
- jwt - 如何在 Istio 中使用授权和 JWT
- c# - Task.Any() 两次调用任务
- ansible - Ansible failed_when 条件不能阻止任务失败