Create gradient border in android?

How to create a gradient border like in the image below?

border

+5
source share
1 answer

You can achieve this by using the list of layers and messing with the addition. You will need 3 elements:

1: The border.xml shape, which is 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" form, the form in which 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 list of layers that will put the 2 on top of each other. You create a border by setting the registration in the internal form: 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"

Indicate here where you want to have the 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 be displayed)

9Patch .

+7

All Articles