如何链接TextView中的文本以打开Web URL

Jai*_*oks 2 java string android hyperlink textview

我花了一个多小时查看大量示例,但实际上没有一个能够在TextView中设置文本以链接到Web URL.

示例代码!

text8 = (TextView) findViewById(R.id.textView4);
text8.setMovementMethod(LinkMovementMethod.getInstance());
Run Code Online (Sandbox Code Playgroud)

strings.xml中

 <string name="urltext"><a href="http://www.google.com">Google</a></string>
Run Code Online (Sandbox Code Playgroud)

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" />
Run Code Online (Sandbox Code Playgroud)

目前此代码将文本显示为"Google",但它没有超链接,点击后没有任何反应.

Jai*_*oks 7

我只是通过以下代码解决了我的问题.

现在,它允许我单击超链接文本"Google",现在打开Web浏览器.

此代码来自以下链接问题的vizZ答案