Search code examples
androidandroid-canvasandroid-drawablexml-drawableandroid-shapedrawable

Custom shape(rounded square) drawable android


I want custom shape border like the one shown below:

enter image description here

This is what i have tried so far:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#00000000"/>
    <stroke android:width="0.1dp" android:color="#FFFFFF" />
    <corners android:radius="5dp"/>
    <!--<padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" />-->
</shape>

But this does not give me curvy sides,only curvy corners.

I need curvy sides


Solution

  • Look at this when change the drawable to this you will get the following output.

     <ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_marginLeft="100dp"
                android:layout_marginTop="25dp"
                android:src="@drawable/rectangle" />
    

    rectangle.xml file is

    <?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="#000000" />
        <stroke
            android:width="1dp"
            android:color="#FFFFFF" />
        <corners android:radius="20dp" />
        <padding
            android:bottom="5dp"
            android:left="5dp"
            android:right="5dp"
            android:top="5dp" />
    </shape>
    

    ScreenShot :

    enter image description here