Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create gradient color border shape in android

in android, I want to define a shape file in drawable folder: myShape.xml such as 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 actually I don't know how! So anyone can give a example of creating shape with gradient color in stroke? Thanks!

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

like image 892
Kingfisher Phuoc Avatar asked Nov 14 '22 00:11

Kingfisher Phuoc


1 Answers

You best option is to use a nine-patch image which has the gradient already set to the desired colors(I don't see any easy way to do that gradient in a xml drawable).

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 nine-patch images for different resolutions(ldpi, hdpi etc)

like image 82
user Avatar answered Dec 18 '22 06:12

user