How do I add a bullet symbol in TextView?

后端 未结 9 1121
感动是毒
感动是毒 2020-11-30 17:27

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

相关标签:
9条回答
  • 2020-11-30 18:06

    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.

    0 讨论(0)
  • 2020-11-30 18:06

    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>
    
    0 讨论(0)
  • 2020-11-30 18:07

    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 "►".

    0 讨论(0)
  • 2020-11-30 18:08

    This worked for me:

    <string name="text_with_bullet">Text with a \u2022</string>
    
    0 讨论(0)
  • 2020-11-30 18:11

    You have to use the right character encoding to accomplish this effect. You could try with &#8226;


    Update

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

    0 讨论(0)
  • 2020-11-30 18:14

    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 drawable left and it worked

    <TextView     
        android:text="Hello bullet"
        android:drawableLeft="@drawable/bulleticon" >
    </TextView>
    
    0 讨论(0)
提交回复
热议问题