How can I create a gradient border like in the image below?
You can achieve this by using a layerlist and messing with the padding. You'll need 3 elements:
1: A border.xml shape, which is just a solid shape in the color of your border: border.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ff0000"/>
</shape>
2: The 'inner' shape, the shape where you want the border to appear around: inner.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00ff00"/>
</shape>
3: A layer list, which will put these 2 on top of eachother. You create the border by setting the padding on the inner shape: layerlist.xml
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/border"/>
<item android:drawable="@drawable/inner"
Specify here where you want to have a stroke(top, left, right, bottom)
android:top="3dp" android:right="0dp" android:bottom="3dp"
android:left="3dp" />
Set this as the background of your TextView, Layout etc. (where you want the stroke to appear)
Or just create a 9Patch image with the borders.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With