简体   繁体   English

如何使用HTML标记 <div> 在字符串textview中

[英]How to use html tag <div> in string textview

I have activity consist of long textview must separated as multiple paragraphs by divider , im using this code : 我的活动由长文本视图组成,必须用分隔符将多个文本分隔为多个段落,即时消息使用以下代码:

TextView tv=(TextView)findViewById(R.id.text); 
        tv.setText(Html.fromHtml(getString(R.string.planet)));

to get the text from strings and using html tags om it as : 从字符串获取文本并使用html标签将其作为:

<string name="planet">
  <![CDATA[ 
    // my text written here//
   ]]> 
 </string>

im try to add separator or divider in between each paragraph by add html divider tag but its not work , i tried this but not working : 即时通讯尝试通过添加html分隔符标签在每个段落之间添加分隔符或分隔符,但它不起作用,我尝试了此操作但不起作用:

 <div class="aligncenter" style="width:400px;height:0;border-top:4px outset 
        #008000;font-size:0;">-</div>

also tried this also not working : 也尝试了这也行不通:

<div align="aligncenter" style="width:400px;height:0;border-top:4px outset 
        #008000;font-size:0;""></div>

so please any advice to apply that divider using htlm tag 所以请提供任何建议以使用htlm标签应用该分隔线

thanks for any help and advice. 感谢您的帮助和建议。

The Html.fromHtml() does not handle all the HTML tags. Html.fromHtml()不能处理所有HTML标记。 Only basic tags like <i> <b> <br/> etc are handled. 仅处理<i> <b> <br/>等基本标签。 For more complex HTML tags that include tags like <span> or <div> use a WebView or you if its just the line break that you want then try a <br/> or a \\n . 对于包含诸如<span><div>类的标记的更复杂的HTML标记,请使用WebView或者如果您只是想要的换行符,请尝试<br/>\\n

Source - Html.fromHtml. 来源 -Html.fromHtml。 Search for handleStartTag on the source page to see more. 在源页面上搜索handleStartTag以查看更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM