Create borders on a android view in drawable xml, on 3 sides?

Try doing this, though I saw it on some other post

<?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="#FFFFFF" />
    <padding
        //android:bottom="10dp"  Remove this to avoid seeing the bottom border 
        android:left="10dp"
        android:right="10dp"
        //android:top="10dp"  Remove this to avoid seeing the top border
    />

    <corners android:radius="5dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
    <padding
        android:bottom="5dp"
        android:left="5dp"
        android:right="5dp"
        android:top="5dp" />

    <solid android:color="#666666" />
</shape>
</item>
</layer-list>

https://stackoverflow.com/a/10133434/1244489


If anyone is running into issues regarding padding taking effect in the accepted answer, try taking a look at: https://stackoverflow.com/a/11006931. That solution uses position attributes on the tags to achieve the same effect.

I was having trouble using the accepted answer here while creating drawables for use in an ActionBar, and the linked approach worked for me.


This might help you.

I The border on Three sides of the XML

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:left="0dp" android:right="0dp" android:top="0dp" android:bottom="-5dp">
        <shape android:shape="rectangle">
            <solid android:color="#ffffff" />

            <corners android:radius="0dp" />
            <stroke android:width="3dp" android:color="#000000" />
        </shape>
    </item>
</layer-list>