java Android:如何在 textview 中为文本提供项目符号、换行符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14708023/
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
Android: how to give bulletpoints, line break to text in textview
提问by teekib
i have a textview with large text in it, but i want to give bulletpoints, line breaks , i tried placing xml entities like •
for bullet point in my string.xml
, but unable to get linebreak and few text comes in the middle, i like to use justify too
我有一个带有大文本的 textview,但我想给出项目符号、换行符,我尝试•
在我的项目中放置像项目符号这样的 xml 实体string.xml
,但无法获得换行符并且中间很少有文本,我喜欢使用 justify也
String nodata="hi how are you<br/>•welcome to stackoverflow"
TextView nodata= ((TextView) findViewById(R.id.nodata));
nodata.setText(Html.fromHtml(nodatafound));
it kind of works but I am unable to use justify , is there any way I can achieve this?
它有点工作,但我无法使用 justify ,有什么办法可以做到这一点吗?
采纳答案by teekib
Thank you all...i finally ended up doing this
谢谢大家……我终于做到了
String nodata="hi how are you<br/>•welcome to stackoverflow"
TextView nodata= ((TextView) findViewById(R.id.nodata));
nodata.setText(Html.fromHtml(nodatafound));
and for justify left i did change in my layout file android:layout_gravity=center|left
并且为了向左对齐,我确实更改了布局文件 android:layout_gravity=center|left
i hope there is a betterway doing this.
我希望有更好的方法来做到这一点。
回答by Ahmad
You forgot the colon after •
你忘记了冒号 •
So change it to this:
所以把它改成这样:
String nodata="hi how are you<br/>•welcome to stackoverflow"
TextView nodata= ((TextView) findViewById(R.id.nodata));
nodata.setText(Html.fromHtml(nodatafound));
回答by User
place this code in strings.xml
将此代码放在strings.xml中
hi how are you \n
嗨,你好吗\n
? welcome to stackoverflow
? 欢迎来到 stackoverflow
set this text to your textview
将此文本设置为您的文本视图
回答by Inzimam Tariq IT
If you wanna do it in java (I means dynamically) use \n
for line break and Unicode character for bullet i.e. \u25CF
.
如果你想在 Java 中(我的意思是动态)使用\n
换行符和 Unicode 字符作为项目符号,即\u25CF
.
This is How I'm using it
这是我如何使用它
textView.setText("Welcome Username\n\u25CF Some Instructions");
It looks as
Welcome Username
● Some Instructions
它看起来像
欢迎用户名
● 一些说明
Your case should be something like
你的情况应该是这样的
textView.setText("hi how are you\n\u25CF welcome to stackoverflow");
Here are some code
这是一些代码
? = \u2022
● = \u25CF
○ = \u25CB
? = \u25AA
■ = \u25A0
□ = \u25A1
? = \u25BA
? = \u2022
●
= \u25CF ○ = \u25CB
? = \u25AA
■ = \u25A0
□ = \u25A1
? = \u25BA
回答by Nipun Gogia
Try this out:
试试这个:
String s = "hello world"
+ System.getProperty ("line.separator")
+ "hello android"
+ System.getProperty ("line.separator");
回答by chaitanya dalvi
Add in string.xml file
<string name="str">•item 1\n •item 2 \n • item 3</string>
在 string.xml 文件中添加
<string name="str">•item 1\n •item 2 \n • item 3</string>