How to define a circle shape in an Android xml drawable file? - ANDROID - Helper

Tuesday, October 16, 2018

How to define a circle shape in an Android xml drawable file?


To draw a circle, we are just using a oval shape with same height and width which results a circle.

1. Create an XML file in the drawable folder

2. Use shape tag and set shape attribute as oval

3. Use solid tag to fill the circle with your custom color

4. Use stroke tag to draw the outline of the circle with your custom color

circle_solid.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#00ff00" />
</shape>

circle_solidstroke.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#00ff00"/>
    <stroke
        android:width="2dp"
        android:color="#ff0000"/>
</shape>

circle_stroke.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <stroke
        android:width="2dp"
        android:color="#ff0000" />
</shape>

Youtube Video



No comments:

Post a Comment