在Android中,有一个容易遗忘的Html.fromhtml方法,意思是可以将比如文本
框中的字符串进行HTML格式化,支持的还是很多的,
但要注意的是要在string.xml中用去转义,比如:
Java代码
"htmlFormattedText">
code
上面就用到了大量的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("今天礼拜五"));
Html.fromHtml("还剩00时26分37秒
秒杀价:54.9")
Html.fromHtml("还剩小于font color='red'大于00时小于font color='red'大于26秒杀价:54.9")