我正在尝试在TextView中添加一个换行符。
我试过建议\n但没用。以下是我设置文本的方式。
TextView txtSubTitle = (TextView)findViewById(r.id.txtSubTitle);
txtSubTitle.setText(Html.fromHtml(getResources().getString(R.string.sample_string)));
这是我的字符串:<string name="sample_string">some test line 1 \n some test line 2</string>
它应该如下所示:
some test line 1
some test line 2
但它是这样显示的:some test line 1 some test line 2
。
我是不是遗漏了什么?
发布于 2011-03-22 06:33:12
好的,想明白了:
<string name="sample_string"><![CDATA[some test line 1 <br />some test line 2]]></string>
因此有必要在CDATA中进行包装,并在其中添加作为html标记分隔符
发布于 2011-08-20 07:06:49
\n
适用于我,如下所示:
<TextView android:text="First line\nNext line"
发布于 2012-05-13 02:09:26
安卓1.6版本无法识别\r\n,请使用: System.getProperty("line.separator")
String s = "Line 1"
+ System.getProperty("line.separator")
+ "Line 2"
+ System.getProperty("line.separator");
https://stackoverflow.com/questions/5382490
复制相似问题