Search code examples
androidandroid-drawableandroid-shape

How to set gradiant color for stroke in shape in Android


I want create custom background and i want create this in drawable folder.
For this background i write below codes :

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <stroke
        android:width="1dp"
        android:color="@color/gradient_center" />

    <corners android:radius="5dp" />

</shape>

but in this code i just set sold color for stroke, i want set gradient color for stroke color.

how can i it?


Solution

  • <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    
    <gradient
        android:angle="90"
        android:endColor="#b5b6d2"
        android:startColor="#555994"
        android:type="linear" />
    
    <corners android:radius="5dp" />
    
    </shape>