我花了一个多小时查看大量示例,但实际上它们都不适用于在TextView中设置文本以链接到Web URL。如何在TextView中链接文本以打开网址
示例代码!
text8 = (TextView) findViewById(R.id.textView4);
text8.setMovementMethod(LinkMovementMethod.getInstance());
的strings.xml
<string name="urltext"><a href="http://www.google.com">Google</a></string>
main.xml中
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:linksClickable="true"
android:text="@string/urltext"
android:textAppearance="?android:attr/textAppearanceMedium" />
目前这个代码显示中的文字为 “谷歌”,然而它不是超链接,什么都不会发生在点击。
据我所知,''标签不字符串资源的支持,除非包裹在'CDATA'。 – CommonsWare
你有没有试过这个http://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable? – Desert
@ user1873880我试过了,它似乎不能正常工作。除非有什么遗漏的东西 –