Pri*_*ria 146 android special-characters textview android-layout
我有一个TextView,我想通过XML在我的文本中添加一个项目符号.可能吗?
Ben*_*erg 327
您必须使用正确的字符编码才能实现此效果.你可以试试•
只是为了澄清:用于setText("\u2022 Bullet");以编程方式添加项目符号.0x2022 = 8226
小智 55
这对我有用:
<string name="text_with_bullet">Text with a \u2022</string>
Run Code Online (Sandbox Code Playgroud)
小智 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>
Run Code Online (Sandbox Code Playgroud)
它的工作方式与您想要的一样,但确实是一种解决方法
小智 8
在任何文本视图中添加项目符号的另一种最佳方法如下两个步骤:
首先,创建一个可绘制的
<?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>
Run Code Online (Sandbox Code Playgroud)
然后在textview中添加这个drawable并使用下面的属性设置它的pedding
android:drawableStart="@drawable/bullet"
android:drawablePadding="10dp"
Run Code Online (Sandbox Code Playgroud)
这就是我最终这样做的方式。
<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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
You may try BulletSpan as described in Android docs.
SpannableString string = new SpannableString("Text with\nBullet point");
string.setSpan(new BulletSpan(40, color, 20), 10, 22, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
Run Code Online (Sandbox Code Playgroud)
使用 Unicode 我们可以轻松完成,但是如果想更改子弹的颜色,我尝试使用彩色子弹图像并将其设置为可绘制的左侧并且它起作用了
<TextView
android:text="Hello bullet"
android:drawableLeft="@drawable/bulleticon" >
</TextView>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
116785 次 |
| 最近记录: |