195

I have a TextView and I want to add a bullet symbol in my text through XML. Is it possible?

Mridang Agarwalla
  • 40,471
  • 69
  • 211
  • 366
Pria
  • 2,603
  • 4
  • 26
  • 30

10 Answers10

435

You have to use the right character encoding to accomplish this effect. You could try with •


Update

Just to clarify: use setText("\u2022 Bullet"); to add the bullet programmatically. 0x2022 = 8226

GreenROBO
  • 4,673
  • 4
  • 22
  • 42
Benny Skogberg
  • 10,051
  • 11
  • 49
  • 82
73

This worked for me:

<string name="text_with_bullet">Text with a \u2022</string>
Sagar Maiyad
  • 12,482
  • 8
  • 60
  • 97
jackbijou
  • 831
  • 6
  • 5
31

Copy paste: •. I've done it with other weird characters, such as ◄ and ►.

Edit: here's an example. The two Buttons at the bottom have android:text="◄" and "►".

Felix
  • 86,568
  • 42
  • 148
  • 166
  • 8
    The problem is when line wraps. It will not indent a 2nd line – Bostone Sep 21 '10 at 21:36
  • 4
    just use a linear layout with orientation horizontal, first textview with "Icon and Space" second :=) the text, => all intended – cV2 Aug 15 '11 at 16:10
19

Prolly a better solution out there somewhere, but this is what I did.

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
        <TableRow>    
            <TextView
                android:layout_column="1"
                android:text="•"></TextView>
            <TextView
                android:layout_column="2"
                android:layout_width="wrap_content"
                android:text="First line"></TextView>
        </TableRow>
        <TableRow>    
            <TextView
                android:layout_column="1"
                android:text="•"></TextView>
            <TextView
                android:layout_column="2"
                android:layout_width="wrap_content"
                android:text="Second line"></TextView>
        </TableRow>
  </TableLayout>

It works like you want, but a workaround really.

The Cageybee
  • 253
  • 2
  • 6
11

You may try BulletSpan as described in Android docs.

SpannableString string = new SpannableString("Text with\nBullet point");
string.setSpan(new BulletSpan(40, color, 20), 10, 22, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

Result

Faisal Naseer
  • 3,913
  • 1
  • 32
  • 54
6

This is how i ended up doing it.

 <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <View
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:background="@drawable/circle"
                android:drawableStart="@drawable/ic_bullet_point" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="Your text"
                android:textColor="#000000"
                android:textSize="14sp" />
        </LinearLayout>

and the code for drawbale/circle.xml is

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:innerRadius="0dp"
  android:shape="ring"
  android:thickness="5dp"
  android:useLevel="false">

 <solid android:color="@color/black1" />

</shape>
Irfan
  • 946
  • 9
  • 15
5

With Unicode we can do it easily, but if want to change color of bullet, I tried with colored bullet image and set it as drawableStart and it worked

<TextView     
    android:text="Hello bullet"
    android:drawableStart="@drawable/bulleticon" >
</TextView>
Ryan M
  • 15,686
  • 29
  • 53
  • 64
Aditya Vyas-Lakhan
  • 13,007
  • 15
  • 58
  • 92
4

Another best way to add bullet in any text view is stated below two steps:

First, create a drawable

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

    <!--set color of the bullet-->
   <solid 
       android:color="#666666"/> //set color of bullet

    <!--set size of the bullet-->
   <size 
       android:width="120dp"
        android:height="120dp"/>
</shape>

Then add this drawable in textview and set its pedding by using below properties

android:drawableStart="@drawable/bullet"
android:drawablePadding="10dp"
0

Since android doesnt support <ol>, <ul> or <li> html elements, I had to do it like this

<string name="names"><![CDATA[<p><h2>List of Names:</h2></p><p>&#8226;name1<br />&#8226;name2<br /></p>]]></string>

if you want to maintain custom space then use </pre> tag

Mightian
  • 7,149
  • 3
  • 39
  • 50
0

(almost) all of the options are about using html tags.

you can use drawables for your TextView if it has only one line of text.

something like this:

<TextView
            android:id="@+id/tv_with_bullet"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            app:drawableStartCompat="@drawable/ic_desired_bullet_icon" />

and add your desired bullet drawable in SVG. it literally takes no space and makes you free of adding complicated string literals. you can also download the SVG file for a bullet point in here