Skip to content

Instantly share code, notes, and snippets.

@SunilDSK
Created November 14, 2016 17:08
Show Gist options
  • Save SunilDSK/fa835466ed4101edfae625f97cb17ac0 to your computer and use it in GitHub Desktop.
Save SunilDSK/fa835466ed4101edfae625f97cb17ac0 to your computer and use it in GitHub Desktop.
Android vector drawable: Dotted round rect
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:color="@color/cardview_dark_background"
android:width="1dp"
android:dashGap="2sp"
android:dashWidth="7dp"/>
<corners android:radius="5dp"/>
</shape>
@SunilDSK
Copy link
Author

Drop this code in some drawable (Ex: roundrect_selectimage.xml). Then use it in "android:background" of any widget like -

  • ImageButton
  • ImageView
  • TextView
  • EditText

An example
Example image

Here I have used a FrameLayout and TextView overlapping the ImageButton (See the event poster sections below code is of only event poster section)
Code

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/posterFrame">

    <ImageButton
        android:id="@+id/imgButton"
        style="?android:attr/borderlessButtonStyle"
        android:background="@drawable/eventposter"
        android:layout_width="200dp"
        android:layout_height="130dp"
        android:layout_gravity="top|center_horizontal"
        android:layout_marginTop="10dp"
        android:scaleType="centerCrop"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|center_vertical"
        android:gravity="center"
        android:text="CLICK HERE \nTO ADD EVENT POSTER"/>

</FrameLayout>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment