html select標簽,Android Html.fromhtml

 2023-10-07 阅读 21 评论 0

摘要:在android中,有一個容易遺忘的Html.fromhtml方法,意思是可以將比如文本 框中的字符串進行HTML格式化,支持的還是很多的, 但要注意的是要在string.xml中用<!--cdata-->去轉義,比如: Java代碼 <string name="htmlF

在android中,有一個容易遺忘的Html.fromhtml方法,意思是可以將比如文本
框中的字符串進行HTML格式化,支持的還是很多的,

但要注意的是要在string.xml中用<!--cdata-->去轉義,比如:

Java代碼

<string name="htmlFormattedText">?

????? <![CDATA[?

????? Text with markup?for?[b]bold[/b]?

????? and [i]italic[/i] text.?

?

????? There is also support?for?a??

????? <tt>teletype-style</tt> font.??

????? But no use?for?the <code>code</code>?

????? tag!?

?

????? ]]></string>

上面就用到了大量的HTML標簽了,JAVA代碼中這樣使用:

Java代碼

TextView view = (TextView)findViewById(R.id.sampleText);?

String formattedText = getString(R.string.htmlFormattedText);?

Spanned result = Html.fromHtml(formattedText);?

view.setText(result);?

或者是這樣寫:

view.setText(Html.fromHtml("<u>今天禮拜天</u>"));

轉載于:https://www.cnblogs.com/lechance/p/4373359.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/123772.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息