如何解决按钮显示的颜色不正确-Android Studio
在我的Android Studio应用程序中,我有一个按钮,将其设置为可绘制背景。可绘制对象圆角化并更改按钮的颜色。 但是,当我查看活动的最终设计时,我想要的颜色没有显示出来。而是,该按钮采用colorPrimary(橙色,#ED3616)。当我运行应用程序时,也会发生同样的情况。 注意:可绘制文件的其他属性可以完美地转换为按钮(即圆角)。问题只在于颜色。
我尝试使用MaterialButton,并使用android:backgroundTint设置颜色。然后,颜色确实出现了,但是设计看起来很奇怪(按钮(Picture of MaterialButton if you'd like to see it里面有一个不同的彩色矩形)
如何使常规按钮具有所需的颜色?
按钮:
<Button
android:background="@drawable/round2"
android:id="@+id/signIn"
android:layout_width="256dp"
android:layout_height="66dp"
android:text="@string/logIn"
android:textColor="#FFFFFF"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.878" />
可绘制:round2.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#B30C44"
android:paddingLeft="6dp"
android:paddingTop="6dp" />
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
<padding
android:bottom="6dp"
android:left="6dp"
android:right="6dp"
android:top="6dp" />
</shape>
显示的内容: What the Button looks like
解决方法
之所以会这样,是因为MaterialButton
的默认样式(如果您使用的是Button
主题,则MaterialButton
会自动替换为MaterialComponents
)tints the background colorPrimary
。
您必须使用:
<Button
android:background="@drawable/round2"
app:backgroundTint="@null"
... />
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。