Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Circular Text Views like Google Messenger

Tags:

android

I would like to display letters inside of circles exactly the way Google Messenger does it, like this:

Google Messenger circular text views

I tried using this drawable file

<?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:color="@color/primary_color" android:width="2dip"/>
<solid android:color="@color/primary_color"/>

as the background for a text view, but that went disastrously wrong. Any ideas?

like image 956
ChristianCuevas Avatar asked Jan 05 '15 22:01

ChristianCuevas


People also ask

What is Google Messages on my Android phone?

Google Messages is described as 'Messages is Google's communications app for Android to helps send and receive SMS and MMS messages. You can also send group texts as well as your favorite pictures, videos and even audio messages to your contacts' and is a Instant Messenger in the Social & Communications category.

How do I Center a circle around a textview in Android?

Create an texview_design.xml file and populate it with the following code. Put it in res/drawable. Second way (not recommended): Download this circle and place it in your drawable folder and then make it your TextView's background. and then set the gravity to center.

What are the best alternatives to Google Messages?

There are more than 10 alternatives to Google Messages for a variety of platforms, including Android, iPhone, Android Tablet, Mac and Windows. The best alternative is Signal, which is both free and Open Source.

What happens when you react to a text message on Google Messages?

For text messages, just like on iMessage, it looks like Google Messages will send the full text of that message back in the reaction, judging from the template. So reacting to the message in the image above would send back a message along the lines of: Liked “¯\_ (ツ)_/¯”.


2 Answers

You was almost close to answer.

Create a drawable resources file under drawable folder: circular_textview.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#4286F5"/>

Set this drawable as your textView's background.

<TextView
    android:layout_width="55dp"
    android:layout_height="55dp"
    android:text="C"
    android:fontFamily="sans-serif-thin"
    android:textColor="#FFF"
    android:textSize="32sp"
    android:gravity="center"
    android:id="@+id/textView"
    android:background="@drawable/circular_textview"/>

That's it

enter image description here

like image 125
M. Reza Nasirloo Avatar answered Sep 20 '22 20:09

M. Reza Nasirloo


This is what I came up with.

I used TextViews with a layer-list background. The background fits the size of the view it's loaded in, so in order to have a circle you can force the TextView to have the same width and height.

<TextView
    android:id="@+id/view"
    android:layout_width="65dp"
    android:layout_height="65dp"
    android:gravity="center"
    android:textSize="40dp"
    android:fontFamily="sans-serif-thin"
    android:background="@drawable/background"
    android:text="A"/>

I have hardcoded text, size, width and height, but you could manage them at runtime. fontFamily="sans-serif-thin" lets you use, if available, the thin typeface which might be better. The layer-list:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:top="1dp">
        <shape android:shape="oval" >
            <solid android:color="#321a1a1a"/>
        </shape>
    </item>
    <item
        android:top="1dp"
        android:bottom="1dp"
        android:left="1dp"
        android:right="1dp">
        <shape android:shape="oval" >
            <solid android:color="@color/red_700"/>
        </shape>
    </item>
</layer-list>

First item is to get the fake shadow shown, but you can get rid of that. Also, you can remove its offset android:top="1dp". This way you will have a circular 1dp ring outside (while now shadow is cast only at the bottom and in both sides).

Again, I have hardcoded colors but you can change to what you want.

like image 25
natario Avatar answered Sep 20 '22 20:09

natario