I have a TextView and I'd like to add border with different colors along its top and bottom edges. I know that inorder to add a border of one color along all edges we can simply use following code:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#000000"/>
</shape>
</item>
<item
android:top="1dp" android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="#ffffff"/>
</shape>
</item>
But what needs to be done if we require edges with different colors?
You're quite close to what you want, what you need to do is add another item below your default item. Those two items are your top/bottom borders. By add bottom/top 1dp to both, you reveal the two colours.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="#000000"/>
</shape>
</item>
<item
android:top="1dp">
<shape android:shape="rectangle">
<solid android:color="#000000"/>
</shape>
</item>
<item
android:top="1dp" android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="#ffffff"/>
</shape>
</item>
</layer-list>
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