JJoe
JJoe

Reputation: 175

How to create notification circle with number in Android?

I need to create a circle with number. But the problem is that some numbers is not in center, for example 1 stayed right from center.

<shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <corners android:radius="18dp"/>
        <solid android:color="@color/black"/>
</shape>

This Drawable is background of TextView

Upvotes: 1

Views: 2063

Answers (3)

Bhumi patel
Bhumi patel

Reputation: 11

Create file xml drawable file.

    <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        >
        <shape
            android:shape="oval">
            <solid android:color="#0288D1" />
        </shape>
    </item>
    <item>
        <shape
            android:shape="oval">
            <stroke android:width="2dp"
                android:color="#FFd200"/>
        </shape>
    </item>
</layer-list>

Upvotes: 1

Mohamed Fiyaz
Mohamed Fiyaz

Reputation: 46

Create a file round.xml in drawable

Set this as backgroundResourse for your textview.

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" android:useLevel="true"
    android:dither="true">
    <solid
        android:color="@android:color/white"/>
    <stroke
        android:color="@color/switcher_grey"
        android:width="@dimen/_1ssp"/>
</shape>

Upvotes: 0

SergeyBukarev
SergeyBukarev

Reputation: 1618

Try use attribute

android:includeFontPadding="false"

 <TextView
    android:layout_width="18dp"
    android:layout_height="18dp"
    android:background="@drawable/test"
    android:gravity="center"
    android:textColor="@color/colorAccent"
    android:includeFontPadding="false"
    android:text="1"/>

enter image description here

Upvotes: 3

Related Questions