如何为卡片设置渐变背景色(来自“材质组件”)

时间:2020-07-15 12:09:15

标签: android material-components-android material-components material-components-cards

我想知道是否可以通过材质组件为卡片设置渐变背景颜色。我正在阅读docs,,但找不到任何内容。

1 个答案:

答案 0 :(得分:1)

在res / drawable下创建一个xml,并将cardview的背景设置为此xml。

 <?xml version="1.0" encoding="utf-8"?>
    <shape android:shape="rectangle"
            xmlns:android="http://schemas.android.com/apk/res/android">
    
        <gradient
                android:startColor="@color/colorPurple"
                android:endColor="@color/colorBlue"
                android:angle="0"/>
    
    </shape>