How to define a circle shape in an Android XML drawable file?
This is a simple circle as a drawable in Android.
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#666666"/> <size android:width="120dp" android:height="120dp"/></shape>
Set this as your view background
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <stroke android:width="1dp" android:color="#78d9ff"/></shape>
For solid circle use:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#48b3ff"/></shape>
Solid with stroke:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#199fff"/> <stroke android:width="2dp" android:color="#444444"/></shape>
Note: To make the oval
shape appear as a circle, in these examples, either your view that you are using this shape as its background should be a square or you have to set the height
and width
properties of the shape tag to an equal value.
Code for Simple circle
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#9F2200"/> <stroke android:width="2dp" android:color="#fff" /> <size android:width="80dp" android:height="80dp"/></shape>