androidxml-drawable

Android how to make custom drawable shape


Hi I want to draw a custom shape in xml like below. How can I draw following shape in android?

How to draw a consultation fee shape in android using xml

square shape.xml:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#ffffffff"/>

    <stroke android:width="3dp"
        android:color="@color/white"
        />

    <padding android:left="1dp"
        android:top="1dp"
        android:right="1dp"
        android:bottom="1dp"
        />

    <corners android:radius="1dp"
        android:bottomRightRadius="1dp" android:bottomLeftRadius="1dp"
        android:topLeftRadius="1dp" android:topRightRadius="1dp"/>
</shape>

Solution

  • Create a new drawable xml named as svg:

    <vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="100dp"
        android:height="100dp"
        android:viewportWidth="100"
        android:viewportHeight="100">
        <path
            android:pathData="M78.2,90L50,61.8 21.8,90V10h56.4v40z"
            android:fillColor="@color/colorPrimary"/>
    </vector>
    

    change pathdata to alter the shape as you prefer...

    Use it in your layout xml for example like:

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/svg">
        
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="My text"
            android:layout_centerInParent="true"/>
    </RelativeLayout>