Html.fromHtml(str)

来源:互联网 发布:松下空调 知乎 编辑:程序博客网 时间:2024/04/30 19:20

txt.setText(Html.fromHtml())


str="

<![CDATA[<b>The Awesome Sliding Up Panel</b><br/> Brought to you by<br/><a href="http://umanoapp.com">http://umanoapp.com</a>]]>
"

格式:

<span style="background-color: rgb(204, 153, 51);"><![CDATA[...]]></span>

TextView设置超链接有两种方法:

1、

TextView txt=new TextView(this);<pre name="code" class="java">String html = "有问题:\n"; html+="<a href='http://www.baidu.com'>百度一下</a>";//注意这里必须加上协议号,即http://<span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; font-size: 14px; line-height: 25.2000007629395px; background-color: rgb(221, 237, 251);">否则,系统会以为该链接是activity,而实际这个activity不存在,程序就崩溃。</span>
txt.setText(Html.fromHtml(html));txt.setMovementMethod(LinkMovementMethod.getInstance);


2、

TextView textView = new TextView(this); String html = "有问题:\n"; html+="www.baidu.com";//这里即使不加协议好HTTP;也能自动被系统识别出来。 textView.setText(html); <span style="background-color: rgb(204, 153, 51);">textView.setAutoLinkMask(Linkify.ALL); </span><span style="color:#666600;">textView.setMovementMethod(LinkMovementMethod.getInstance()); </span>


0 0