Create a shape in Android

Web

All about Shapes can be found here. A simplest example of how to create a shape is the code snippet below. Save this xml under the drawable folder.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FFFF0000"
android:endColor="#80FF00FF"
android:angle="45"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<corners android:radius="8dp" />
</shape>

To use this shape, just set the background property of an layout element using the “@drawable/shape_file_name”.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/colors"
android:layout_width="match_parent">
</RelativeLayout>

 

 image