zoukankan      html  css  js  c++  java
  • Android Html.fromhtml

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

  • 相关阅读:
    素数
    超级素数
    SUMMARIZE 6.1
    广度优先搜索与八字码问题
    poj2352
    poj1198
    康托展开
    STL里的内存池实现
    构造函数,C++内存管理,内存泄漏定位
    内联函数,宏定义,内存对齐,类型转换
  • 原文地址:https://www.cnblogs.com/lechance/p/4373359.html
Copyright © 2011-2022 走看看