Create gradient color border in android

in android, I want to define a shape file in the drawable : myShape.xml , for example below:

  <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/white"/> <corners android:radius="@dimen/corner"/> <stroke android:width="5dp" android:color="@color/boder_endcall_color"/> </shape> 

And I want to create a gradient border in <stroke /> , but I really don't know how to do it! So, can anyone give an example of creating a shape with a gradient color in stroke ? Thanks!

Edit: I want a gradient color from #F85C5C (red) to #F68282 (reddish).

+4
source share
1 answer

It’s best to use an image with nine patches that already has the gradient necessary for the desired colors (I don’t see any easy way to make this gradient in an xml drawing).

For example, using your colors here is such a nine patch (ignore my awful design skills):

nine-patch image

Of course, for best results you should have different images with nine patches for different resolutions (ldpi, hdpi, etc.)

+1
source

All Articles