Tuesday, January 13, 2015

How to add a dotted border in a Button in Android

activity_main.xml code snippet

<Button
 android:id ="@+id/push_button"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Button Dotted Border"
 android:padding="15dp"
 android:background="@drawable/button_dotted_border"
 />
res/drawable/button_dotted_border.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <solid android:color="#F0E68C"/>
        <!--stroke create dot by 2dp width 2dp gap and 2dp height-->
        <stroke
            android:color="#DC143C"
            android:width="2dp"
            android:dashWidth="2dp"
            android:dashGap="2dp"
            />
    </shape>
</item>
</selector>
More android examples