我正在尝试在Button中设置渐变颜色(在android演播室,其版本是北极福克斯)。
gradientbuttonmainactivity.xml,我把这个文件绘制成可绘制的。
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#93501C"
android:endColor="#A67E7E"
android:type="linear"
android:angle="360"/>
<corners
android:radius="25dp"/>
</shape>activity_main.xml
<Button
android:id="@+id/btnR"
android:layout_width="275dp"
android:layout_height="55dp"
android:layout_marginStart="55dp"
android:layout_marginTop="25dp"
android:background="@drawable/gradientbuttonmainactivity"
android:text="@string/register" />但是按钮的颜色和它一样,角点值被应用,但是梯度值没有。
我在谷歌上搜索过,但没有找到任何可行的解决方案。在一个堆栈溢出的答案中,一位作者说要用colorPrimary (在theme.xml中)更改@null。我这样做了,并应用了渐变颜色,但在运行时,应用程序未能在智能手机中打开,然而,它成功启动。
所以,问题很清楚,如何使按钮具有渐变的颜色?谢谢。
发布于 2021-09-10 11:01:40
作为另一种选择,尝试使用
androidx.appcompat.widget.AppCompatButton
而不是
按钮
这可能是最近对Button和Android的材料设计的改变,我注意到在旧的项目中,您用Button实现了哪些工作,但是在最近的一个项目中,这个背景不起作用。
https://stackoverflow.com/questions/69130702
复制相似问题