一、问题描述
在设置button背景颜色后,button背景依旧为蓝色。如下所示:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HelloWorld"
android:textSize="50sp"
android:background="@color/purple_200"
/>
二、问题缘由 / 解决
在使用Android Studio 4.1+ 进行开发时,创建的项目默认的主题是Theme.MaterialComponents.DayNight.DarkActionBar
。所有Button都是Material类型的Button,默认使用主题色。
解决方法:
- 将主题切换为:Theme.AppCompat.*** , 不使用Material控件
<style name="Theme.ShapePractice" parent="Theme.AppCompat.DayNight.DarkActionBar">
- 设置
android:backgroundTint="@null"
着色设置为null后再进行背景设置
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:backgroundTint="@null"
android:background="@color/purple_200"
android:text="HelloWorld"
android:textSize="50sp" />
参考
android – How to change the color of a button? – Stack Overflow
© 版权声明
文章版权归作者所有,未经允许请勿转载。如内容涉嫌侵权,请在本页底部进入<联系我们>进行举报投诉!
THE END
暂无评论内容