我花了一个多小时查看大量示例,但实际上没有一个可用于在 TextView 中设置文本以链接到 Web URL。
示例代码!
text8 = (TextView) findViewById(R.id.textView4);
text8.setMovementMethod(LinkMovementMethod.getInstance());
字符串.xml
<string name="urltext"><a href="http://www.google.com">Google</a></string>
主要的.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" />
目前,此代码将文本显示为“Google”,但它没有超链接,点击后没有任何反应。