如何使 TextView 中的普通链接可点击? [英] How to make normal links in TextView clickable?

查看:26
本文介绍了如何使 TextView 中的普通链接可点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Android 应用中,我有一个 TextView.文本可以包含链接.这是一个文本示例:

In my Android app, I have a TextView. The text can contain links. This is an example of a text:

这只是一个测试.点击以下链接 http://www.google.com 访问 Google.

注意文本不在HTML中;它将只是一个普通文本.

Note that the text is not in HTML; it will be just a regular text.

我想做一些类似 textView.parseLinks() 的事情,然后在 TextView 中,http://www.google.com将被超链接并可以点击以打开页面.

I want to do something like textView.parseLinks(), then in the TextView, http://www.google.com will be hyper-linked and clickable to open up the page.

这可能吗?

谢谢

推荐答案

尝试在 XML 文件中的 TextView 定义中包含以下内容:

Try and include the following in the TextView definition in XML file:

<TextView
    ...
    android:autoLink="web"/>

android:autoLink 的文档说:

控制是否自动找到 url 和电子邮件地址等链接并将其转换为可点击的链接

Controls whether links such as urls and email addresses are automatically found and converted to clickable links

因此对于自动查找链接,上述内容可能会有所帮助.试试看.

So for automatically finding links, the above may help. Try and see.

这篇关于如何使 TextView 中的普通链接可点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆