我希望用CardView重新创建下面的图像。为此,我创建了一个渐变文件(btn_gradient.xml),然后继续创建CardView。
CardView实现:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="44dp"
android:layout_margin="25dp"
app:cardElevation="0dp"
app:cardCornerRadius="4dp"
app:cardPreventCornerOverlap="false">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@drawable/btn_gradient"
android:text="Create Account"
android:textColor="#000000"
android:textStyle="bold"
android:textAllCaps="false"/>
</android.support.v7.widget.CardView>
这种方式一切正常,但半径消失了,这不是我想要的。有没有办法可以直接在CardView上设置渐变?cardBackgroundColor
属性只接受颜色,而不接受可绘制对象。感谢任何帮助。 补充:
按照要求,这是我的btn_gradient.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:type="linear"
android:angle="0"
android:startColor="#ffc200"
android:endColor="#fca10b" />
</shape>