来自带有链接结束文本的字符串的可点击链接

发布于 2025-01-06 14:22:50 字数 535 浏览 3 评论 0原文

我需要制作带有网页链接的文本。我使用该代码但不起作用:

licence = (TextView)findViewById(R.id.about_text5);
final SpannableString s = new SpannableString(Html.fromHtml("The ipiit Team\n\nFYI:        This software contains the <a href=\"http://code.google.com/p/zxing\">zxing</a> component licensed under <a href=\"http://httpd.apache.org/docs/2.0/license.html\">Apache 2.0</a>.\n\n"));
Linkify.addLinks(s, Linkify.WEB_URLS);
licence.setText(s);
licence.setMovementMethod(LinkMovementMethod.getInstance()); 

I need to make text with links to webpages. I use that code but is not working:

licence = (TextView)findViewById(R.id.about_text5);
final SpannableString s = new SpannableString(Html.fromHtml("The ipiit Team\n\nFYI:        This software contains the <a href=\"http://code.google.com/p/zxing\">zxing</a> component licensed under <a href=\"http://httpd.apache.org/docs/2.0/license.html\">Apache 2.0</a>.\n\n"));
Linkify.addLinks(s, Linkify.WEB_URLS);
licence.setText(s);
licence.setMovementMethod(LinkMovementMethod.getInstance()); 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡写薰衣草的香 2025-01-13 14:22:50

我认为应该是...

Linkify.addLinks(licence , Linkify.WEB_URLS);

而不是

Linkify.addLinks(s, Linkify.WEB_URLS);

因为您已经将 Spannable 文本设置为 TextView,所以在 TextView 上调用 addLinks...

I think it should be...

Linkify.addLinks(licence , Linkify.WEB_URLS);

and not

Linkify.addLinks(s, Linkify.WEB_URLS);

because you are already setting your Spannable text to your TextView, so call addLinks on the TextView...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文