Rectange Shape Drawable
Below example defines rectangle shape drawable with gradient and round corners. Attributes of the gradient element lets you define center of gradient on x and y axis, angle of gradient 0(left to right), 45 or 90(bottom to top), start, end and center colors and type of gradient (radial, linear and sweep).
Oval Shape Drawable
You can create oval shape drawable as shown below and apply it to button to create oval shaped button.
Ring Shape Drawable
To create ring shape drawable, you need to set shape, innerRadius and thichkness attributes of shape element. Below screen shows round buttons which you can create by setting background attribute of a button to ring shape drawable.
To adjust the ring around view, you need to set padding in the definition of ring shape drawable. You can set ring color using solid or gradient elements of shape
To define line shape drawable, you need to set shape attribute of shape element to line and add storke element with color and size element.
Below example defines rectangle shape drawable with gradient and round corners. Attributes of the gradient element lets you define center of gradient on x and y axis, angle of gradient 0(left to right), 45 or 90(bottom to top), start, end and center colors and type of gradient (radial, linear and sweep).
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="0"
android:centerX="0.1"
android:centerY="0.1"
android:centerColor="#1976d2"
android:startColor="#00e5ff"
android:endColor="#6200ea"
android:gradientRadius="100"
android:type="linear"/>
<padding android:left="5dp"
android:top="4dp"
android:right="4dp"
android:bottom="4dp" />
<corners android:radius="6dp" />
</shape>
Oval Shape Drawable
You can create oval shape drawable as shown below and apply it to button to create oval shaped button.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/colorPrimary"/>
</shape>
Ring Shape Drawable
To create ring shape drawable, you need to set shape, innerRadius and thichkness attributes of shape element. Below screen shows round buttons which you can create by setting background attribute of a button to ring shape drawable.
To adjust the ring around view, you need to set padding in the definition of ring shape drawable. You can set ring color using solid or gradient elements of shape
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="20dp"
android:shape="ring"
android:thickness="10dp"
android:useLevel="false">
<solid android:color="@color/colorPrimary" />
<padding android:bottom="50dp"
android:left="16dp"
android:right="16dp"
android:top="50dp"/>
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="ring"
android:thickness="40dp"
android:useLevel="false">
<gradient
android:angle="0"
android:centerX="0.2"
android:centerY="0.6"
android:centerColor="#b60862"
android:startColor="#ba68c8"
android:endColor="#dd2c00"
android:gradientRadius="120"
android:type="sweep"/>
<padding android:bottom="50dp"
android:left="16dp"
android:right="16dp"
android:top="50dp"/>
</shape>
<?xml version="1.0" encoding="utf-8"?>Line Shape Drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="8dp"
android:shape="ring"
android:thickness="30dp"
android:useLevel="false">
<gradient
android:angle="0"
android:centerX="0.1"
android:centerY="0.1"
android:centerColor="#b60862"
android:startColor="#ba68c8"
android:endColor="#dd2c00"
android:gradientRadius="120"
android:type="sweep"/>
<padding android:bottom="50dp"
android:left="16dp"
android:right="16dp"
android:top="50dp"/>
</shape>
To define line shape drawable, you need to set shape attribute of shape element to line and add storke element with color and size element.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="20dp"
android:color="#b71c1c" />
<size android:height="8dp" />
</shape>