Tuesday, January 13, 2015

How to add a dashed border to a Button in Android

Button Dashed Border
activity_main.xml code snippet

<Button
 android:id ="@+id/push_button"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Button Dashed Border"
 android:padding="15dp"
 android:background="@drawable/button_bg_dashed_border"
 />
res/drawable/button_bg_dashed_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="#BDB76B"/>
        <stroke
            android:color="#006400"
            android:width="2dp"
            android:dashGap="4dp"
            android:dashWidth="10dp"
            />
    </shape>
</item>
</selector>
More android examples