Text View with circular background

Using the following code:

White_circle_drawable.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="oval">
    <solid android:color="#A6ffffff"/>
    <stroke android:width="0dp" android:color="#fff" />
    <size android:width="28dp" android:height="28dp"/>
</shape>

TextView

<TextView
    android:id="@+id/TextViewID"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:paddingTop="5dp"
    android:text="2"
    android:layout_marginTop="2dp"
    android:layout_marginBottom="2dp"
    android:gravity="center"
    android:visibility="gone"
    android:textColor="#ff2800"                
    android:background="@drawable/white_circle_drawable"
    android:textSize="13sp" />

Here is solution :

circular_textview.xml code

<?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="oval" >
        <corners android:radius="10dip" />
    <stroke
         android:width="5dip"
         android:color="@color/red" />
   <solid android:color="@color/red" />

Here is textView in main.xml

            <TextView
                android:layout_width="27dp"
                android:layout_height="27dp"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="5dp"
              android:background="@drawable/circular_textview"
                android:gravity="center"
                android:padding="5dp"
                android:text="@string/tag_2"
                android:textColor="@color/white"
                android:textSize="12sp" />

This will help you.


such great answers up there, I am going to add my way.

first, create a drawable file and add the following code and you should be good to go.

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#A6E41010" />
<size
android:width="36dp"
android:height="36dp" />
<corners android:radius="18dp" />
</shape> 

Tags:

Xml

Android