Android 如何在 TextView 中添加项目符号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3429546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I add a bullet symbol in TextView?
提问by Pria
I have a TextView and I want to add a bullet symbol in my text through XML. Is it possible?
我有一个 TextView,我想通过 XML 在我的文本中添加一个项目符号。是否可以?
回答by Benny Skogberg
You have to use the right character encodingto accomplish this effect. You could try with •
您必须使用正确的字符编码来实现此效果。你可以试试•
Update
更新
Just to clarify: use setText("\u2022 Bullet");
to add the bullet programmatically. 0x2022 = 8226
只是为了澄清:用于setText("\u2022 Bullet");
以编程方式添加项目符号。0x2022 = 8226
回答by Hymanbijou
This worked for me:
这对我有用:
<string name="text_with_bullet">Text with a \u2022</string>
回答by Felix
回答by The Cageybee
Prolly a better solution out there somewhere, but this is what I did.
Prolly 在某个地方有一个更好的解决方案,但这就是我所做的。
<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.
它可以像您想要的那样工作,但确实是一种解决方法。
回答by Faisal Naseer
You may try BulletSpanas described in Android docs.
您可以按照 Android 文档中的说明尝试BulletSpan。
SpannableString string = new SpannableString("Text with\nBullet point");
string.setSpan(new BulletSpan(40, color, 20), 10, 22, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
回答by Irfan
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
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>
回答by Aditya Vyas-Lakhan
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
使用 Unicode 我们可以轻松完成,但是如果想更改项目符号的颜色,我尝试使用彩色项目符号图像并将其设置为可绘制左侧并且它起作用了
<TextView
android:text="Hello bullet"
android:drawableLeft="@drawable/bulleticon" >
</TextView>
回答by Mightian
Since android doesnt support <ol>, <ul> or <li>
html elements, I had to do it like this
由于android不支持<ol>, <ul> or <li>
html元素,我不得不这样做
<string name="names"><![CDATA[<p><h2>List of Names:</h2></p><p>•name1<br />•name2<br /></p>]]></string>
if you want to maintain custom space then use </pre> tag
如果您想维护自定义空间,请使用 </pre> tag