in Android, Android Code Tips, Programming

Android shape xml example

Shapes in Android are extremely useful but there are not enough examples.

The values for the shape attribute are: rectangle, oval, line and ring.

Here is a simple (and ugly) example but you can get the point:

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

        <solid android:color="#ff0000"/>

	<gradient android:startColor="#ffffff" android:endColor="#000000"
		android:angle="180" />


	<stroke android:width="1dp" android:color="#FF000000"
		android:dashWidth="1dp" android:dashGap="2dp" />
         <!-- or -->
	<stroke android:width="1dp" android:color="#FF00FF00" />


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

	<corners android:bottomRightRadius="9dip"
		android:bottomLeftRadius="9dip" android:topLeftRadius="9dip"
		android:topRightRadius="9dip" />

</shape>

Check the documentation here for more details.

Share