androidxmlshapesandroid-shapeandroid-shapedrawable

How do you make a line drawable with a gradient?


So...I wanted to add a line that looks like this line with gradient and have created a drawable


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

        <stroke
            android:color="#000000"
            android:width="1dp"/>
        <gradient android:startColor="#FFEE8D85"
            android:endColor="#000000"/>
    </shape>
</rotate>

which gives this result line without gradient what do I do to get the desired result I want?


Solution

  • Make drawable resourse file.

    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <gradient
            android:type="linear"
            android:angle="90"
            android:startColor="#14b19e"
            android:endColor="#115ede" />
    </shape>
    

    Then apply like this

    <View
        android:layout_width="1dp"
        android:layout_height="50dp"
        android:background="@drawable/my_gradient_drawable"/>