如何在TextView中添加项目符号?

时间:2010-08-07 07:22:51

标签: android android-layout special-characters textview

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

9 个答案:

答案 0 :(得分:306)

您必须使用正确的character encoding来完成此效果。您可以尝试使用•


更新

只是为了澄清:使用setText("\u2022 Bullet");以编程方式添加项目符号。 0x2022 = 8226

答案 1 :(得分:52)

这对我有用:

<string name="text_with_bullet">Text with a \u2022</string>

答案 2 :(得分:25)

复制粘贴:•。我已经用其他奇怪的字符完成了它,例如◄和►。

修改: here就是一个例子。底部的两个Button包含android:text="◄""►"

答案 3 :(得分:17)

在某处提供更好的解决方案,但这就是我所做的。

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

它的工作方式与您想要的一样,但确实是一种解决方法。

答案 4 :(得分:4)

使用Unicode,我们可以轻松完成,但如果想改变子弹的颜色,我尝试使用彩色子弹图像并将其设置为可绘制的左侧并且可以使用

<TextView     
    android:text="Hello bullet"
    android:drawableLeft="@drawable/bulleticon" >
</TextView>

答案 5 :(得分:4)

这就是我最终如何做到这一点。

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

答案 6 :(得分:1)

您可以按照Android文档中的说明尝试BulletSpan

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

Result

答案 7 :(得分:0)

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

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

如果您想维护自定义空间,请使用</pre> tag

答案 8 :(得分:0)

在任何文本视图中添加项目符号的另一种最佳方法是以下两个步骤:

首先,创建一个可绘制对象

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

然后在textview中添加此drawable并使用以下属性设置其pedding

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