我怎样才能使fromHTML可点击的链接? (安卓) [英] How can I make links in fromHTML clickable? (Android)

查看:129
本文介绍了我怎样才能使fromHTML可点击的链接? (安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个微不足道的问题,但有一种我难住了。我想加载使用Html.fromHtml()的HTML字符串,并在字符串中的任何链接被点击并打开浏览器。

This seems like a trivial problem, but is has me kind of stumped. I want to load an HTML string using Html.fromHtml(), and have any links in the string to be clickable and open in the browser.

基本例如:

textView.setText(Html.fromHtml("<a href=\"http://www.google.com\">This is a link</a>"));

在这个片段中,该文本的格式,好像它是一个链接(蓝色下划线),但它不能点击。我试过Linkify,但似乎只与没有基于HTML的联系工作。

With this snippet, the text is formatted as if it were a link (blue, underlined), but it's not clickable. I tried Linkify, but it only seems to work with links that are not HTML-based.

有什么建议?

推荐答案

正如我认为,解决的办法很简单:

As I assumed, the solution was trivial:

textView.setText(Html.fromHtml("<a href=\"http://www.google.com\">This is a link</a>"));
textView.setMovementMethod(LinkMovementMethod.getInstance());

第二行以某种方​​式激活链接行为,虽然我不太清楚如何。同样的问题是解决了在谷歌code

这篇关于我怎样才能使fromHTML可点击的链接? (安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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