源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Android中html.fromhtml的使用方法

  • 时间:2022-05-05 01:35 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android中html.fromhtml的使用方法
[b]Android中html.fromhtml[/b]   在android中,有一个容易遗忘的Html.fromhtml方法,意思是可以将比如文本 框中的字符串进行HTML格式化,支持的还是很多的, 但要注意的是要在string.xml中用<!--cdata-->去转义,比如:

<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代码中这样使用:
TextView view = (TextView)findViewById(R.id.sampleText); 
String formattedText = getString(R.string.htmlFormattedText); 
Spanned result = Html.fromHtml(formattedText); 
view.setText(result); 
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部