Search code examples
androidandroid-drawableandroid-vectordrawable

How can I create gradient border color


I'm looking to create something such as button below :

enter image description here

I know how to create it like this but I want it with gradient border color.


Solution

  • Try This:

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item>
            <!-- create gradient you want to use with the angle you want to use -->
            <shape android:shape="rectangle">
                <gradient
                    android:angle="0"
                    android:centerColor="@android:color/holo_blue_bright"
                    android:endColor="@android:color/holo_red_light"
                    android:startColor="@android:color/holo_green_light" />
                <corners android:radius="@dimen/dp_10"/>
    
            </shape>
        </item>
        <!-- create the stroke for top, left, bottom and right with the dp you want -->
        <item
            android:bottom="2dp"
            android:left="2dp"
            android:right="2dp"
            android:top="2dp">
            <shape android:shape="rectangle" >
                <!-- fill the inside in the color you want (could also be a gradient again if you want to, just change solid to gradient and enter angle, start, maybe center, and end color) -->
                <solid android:color="#fff" />
                <corners android:radius="@dimen/dp_10"/>
            </shape>
        </item>
    
    </layer-list>
    

    chose the color you want..