我有一个TextView,我想通过XML在我的文本中添加一个子弹符号。这可能吗?


当前回答

这就是我最后怎么做的。

 <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>

drawbale/circle.xml的代码是

<?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>

其他回答

由于android不支持<ol>, <ul>或<li> html元素,我必须这样做

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

如果你想保持自定义空间,那么使用</pre>标签

复制粘贴:我还用过其他一些奇怪的文字,比如“京城”和“►”。

编辑:这里有一个例子。最下面的两个按钮分别是“text=”和“►”。

您必须使用正确的字符编码来实现此效果。你可以试试&#8226;

更新

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

这就是我最后怎么做的。

 <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>

drawbale/circle.xml的代码是

<?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>

你可以尝试Android文档中描述的BulletSpan。

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