Android: defining border drawables in xml

The following border can apply to TextView, LinearLayout, RelativeLayout, or any other views by setting the background to those drawable xml files. android:background="@drawable/border_bottom"

Top Border

drawable/border_top.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:bottom="-2dp" android:left="-2dp" android:right="-2dp">
        <shape android:shape="rectangle">
            <stroke android:width="1dp" android:color="#000" />
        </shape>
    </item>
</layer-list>

Bottom Border

drawable/border_bottom.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:top="-2dp" android:left="-2dp" android:right="-2dp">
        <shape android:shape="rectangle">
            <stroke android:width="1dp" android:color="#000" />
        </shape>
    </item>
</layer-list>

Left Border

drawable/border_left.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:top="-2dp" android:bottom="-2dp" android:right="-2dp">
        <shape android:shape="rectangle">
            <stroke android:width="1dp" android:color="#000" />
        </shape>
    </item>
</layer-list>

Right Border

drawable/border_right.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:top="-2dp" android:bottom="-2dp" android:left="-2dp">
        <shape android:shape="rectangle">
            <stroke android:width="1dp" android:color="#000" />
        </shape>
    </item>
</layer-list>

Full Border

drawable/border_right.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <stroke android:width="1dp" android:color="#000" />
        </shape>
    </item>
</layer-list>

Search within Codexpedia

Custom Search

Search the entire web

Custom Search