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


当前回答

肯定有更好的解决办法,但我就是这么做的。

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

就像你想要的那样,但实际上是一种变通方法。

其他回答

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

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

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

更新

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

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

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

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

使用Unicode我们可以很容易地做到这一点,但如果想改变子弹的颜色,我尝试了彩色子弹图像,并将其设置为drawableStart,它工作

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

肯定有更好的解决办法,但我就是这么做的。

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

就像你想要的那样,但实际上是一种变通方法。