Andorid中Html.fromHtml技巧
发布时间:2021-11-22 12:55:50 所属栏目:教程 来源:互联网
导读:在Android中,有一个容易遗忘的Html.fromhtml方法,意思是可以将比如文本 框中的字符串进行HTML格式化,支持的还是很多的, 但要注意的是要在string.xml中用!--cdata--去转义,比如: Java代码 string name=htmlFormattedText ![CDATA[ Text with markup for
在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>")); (编辑:东莞站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |