【发布时间】:2014-04-15 09:00:34
【问题描述】:
我在布局中有一个TextView
<TextView
android:id="@+id/homepage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
我想在这个TextView中设置一个带有HTML链接的字符串,并使链接可点击(在浏览器中打开链接时点击)。我尝试了以下方法:
我在资源中定义了字符串,该字符串包含一个指向谷歌网站的 HTML 链接:
<string name="home_page">please go to <a ref="www.google.com">www.google.com!</a>.
在我的活动中:
TextView homepage = (TextView)findViewById(R.id.homepage);
String text = getString(R.string.home_page)
CharSequence styledText = Html.fromHtml(text);
homepage.setText(styledText.toString());
结果是 please go to www.google.com ,但 www.google.com 不是可点击的链接。如何让它可点击? (我的意思是点击时在浏览器中打开链接)
【问题讨论】:
-
为此目的使用可点击的跨度。 chrisumbel.com/article/…