android - 如何使 Textview 可点击,以便它在网络浏览器中打开 url

标签 android

很抱歉问这个新手问题,因为我是 android 开发的新手。 main.java 中应该输入什么代码?

<resources>
<string name="strname">Clickable Text<a href="http://domain.com">Visit Website</a></string>
</resources>



<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:autoLink="web"
android:text="@string/strname"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />

最佳答案

你可以使用Linkfy :

TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("http://www.google.com");
Linkify.addLinks(textView, Linkify.WEB_URLS);

来自文档

Linkify take a piece of text and a regular expression and turns all of the regex matches in the text into clickable links

关于android - 如何使 Textview 可点击,以便它在网络浏览器中打开 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28381809/

相关文章:

android - float 操作按钮图标未在内部居中

java - 业务对象中的应用程序上下文

java - 将方法调用包装在新对象中有什么好处?

android - 仅在某些工作区中构建路径不完整(Android)

android - 如何在kotlin fragment 类的 View 模型中调用接口(interface)方法

android - 双向数据绑定(bind) : View is missing user defined type

java - 更改微调项目中的字体

android - 定期从服务器获取数据的最佳方式

android - 数据库更新协程完成后,设置 bool 标志

android - Twilio SMS 正文不会连接 Azure 逻辑应用程序中的 URL 参数