我在佈局TextView
集TextView中包含一個可點擊的HTML鏈接
<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());
結果請到到www.google.com,但www.google.com不是可點擊的鏈接。如何使它可點擊? (我的意思是打開瀏覽器的鏈接被點擊時)
爲此使用可點擊跨度。 http://www.chrisumbel.com/article/android_textview_rich_text_spannablestring – Raghunandan