How do I add a bullet symbol in TextView?

2019-01-08 04:19发布

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

7条回答
狗以群分
2楼-- · 2019-01-08 04:58

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.

查看更多
叛逆
3楼-- · 2019-01-08 05:01

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>
查看更多
闹够了就滚
4楼-- · 2019-01-08 05:10

This worked for me:

<string name="text_with_bullet">Text with a \u2022</string>
查看更多
看我几分像从前
5楼-- · 2019-01-08 05:12

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

查看更多
戒情不戒烟
6楼-- · 2019-01-08 05:13

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

查看更多
冷血范
7楼-- · 2019-01-08 05:14

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>
查看更多
登录 后发表回答