首页 > Web开发 > 详细

andorid中Html.fromHtml方法

时间:2014-10-30 15:03:33      阅读:196      评论:0      收藏:0      [点我收藏+]

在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>"));

andorid中Html.fromHtml方法

原文:http://www.cnblogs.com/yiludugufei/p/4062410.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!