我有一个字符串,它将被我的下一个类中的intentExtra拾取并被设置为多行TextView的文本。如果有一种方法可以将文本分开以便它们在彼此之下,那么我很想知道,所以我有这个字符串:
maint = "Here is some info about nothing." +
"Some more info about nothing." +
"And a little more about nothing";
通常它们会显示在textView中,如下所示:
Here is some info about nothing. Some more info about nothing. And a little more info about nothing.
是否有一种方法可以在每个单独的部分写入TextView之后结束这一行
像这样:Here is some info about nothing.
Some more info about nothing.
And a little more about nothing.
对于每个单独的句子来说,似乎对于单独的TextView来说太过分了。
提前致谢
答案 0 :(得分:3)
将/ n添加到您想要换行的位置。
maint = "Here is some info about nothing.\n" +
"Some more info about nothing.\n" +
"And a little more about nothing";
您也可以使用Html对其进行格式化。添加您想要换行的位置。
maint = "Here is some info about nothing.</br>" +
"Some more info about nothing.</br>" +
"And a little more about nothing";
如果使用HTML格式化它,则需要先将其解析,然后再将其传递给textview:
myTextView.setText(Html.fromHtml(maint));
答案 1 :(得分:1)
这应该做你想要的(“\ n”是换行符)
maint = "Here is some info about nothing.\n" +
"Some more info about nothing.\n" +
"And a little more about nothing\n";