How to set a Gradient Background Color to a Card (from Material Components)

Viewed 490

I was wondering if there is any way to set a gradient background color to a Card from the Material Components. I was reading through the docs, but I couldn't find anything.

1 Answers

Create an xml below res/drawable and set the background of your cardview to this 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>
Related