[android studio]Android中html.fromhtml的使用方法

更新时间:2021-06-10    来源:文本特效    手机版     字体:

【www.bbyears.com--文本特效】

Android中html.fromhtml

在android中,有一个容易遗忘的Html.fromhtml方法,意思是可以将比如文本 框中的字符串进行HTML格式化,支持的还是很多的,

但要注意的是要在string.xml中用去转义,比如:

 代码如下

   

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

   and [i]italic[/i] text.

  

   There is also support for a 

   teletype-style font. 

   But no use for the code

   tag!

  

   ]]>

上面就用到了大量的HTML标签了,JAVA代码中这样使用:

 代码如下

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

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

Spanned result = Html.fromHtml(formattedText);

view.setText(result);

本文来源:http://www.bbyears.com/wangyetexiao/122956.html

热门标签

更多>>

本类排行