【问题标题】:Html tag is not supporting "\n"(new line) in androidhtml标签不支持android中的“\n”(新行)
【发布时间】:2015-08-21 09:42:39
【问题描述】:
static String test2 = " <h1> THis is the \n test </h1>";
TextView tst;
tst.setText(Html.fromHtml(test2));

输出:

这是测试

所需输出:

这是
测试

不将“\n”替换为“
”有可能吗??

【问题讨论】:

  • &lt;br&gt;代替\n?

标签: android html newline line-breaks


【解决方案1】:

\n&lt;br&gt; 之间存在差异。

"&lt;br&gt;" 是换行符的 HTML 标签,而\n 是 Unix 标签,它将在渲染的源代码中显示换行符,但在大多数情况下不会在渲染的视图中显示。

【讨论】:

    【解决方案2】:

    \n 在 HMTL 中不起作用,您应该在 html 中使用&lt;br&gt; 标记换行

    static String test2 = " <h1> THis is the <br> test </h1>";
    

    【讨论】:

      【解决方案3】:

      您也可以通过将 \n 放在双引号中来在 XML 中执行此操作

      制作字符串资源

      <string name="htmltext"><u><i>Project Title</i></u><u>Smart City Apps</u>+"\n"+Developed by Stack.</string>
      android:text="@string/htmltext"/>
      

      【讨论】:

        猜你喜欢
        • 2012-04-15
        • 2017-11-08
        • 1970-01-01
        • 1970-01-01
        • 2016-04-24
        • 2023-03-14
        • 1970-01-01
        • 2011-06-06
        • 1970-01-01
        相关资源
        最近更新 更多