gpt4 book ai didi

android - 获取链接信息android

转载 作者:行者123 更新时间:2023-11-29 01:43:56 26 4
gpt4 key购买 nike

我们如何在 android 中显示有关链接的一些附加信息我已经看到在浏览器中打开链接的例子,但我想要的不是这种情况

 TextView tv = (TextView) findViewById(R.id.textView1);
String text = "This is just a test. Click this link here <a href=\"http://www.google.com\">Google</a> to visit google.";
tv.setMovementMethod(LinkMovementMethod.getInstance());
tv.setText(Html.fromHtml(text));

我已经尝试了一些类似上面的代码,但它是用于在浏览器中打开的,我还想要像下图这样的东西

enter image description here

最佳答案

这可以使用 URLSpan 来完成.

TextView tv = (TextView) findViewById(R.id.textView1);
SpannableString text = new SpannableString("This is just a test. Click this link here to visit google.");
text.setSpan(new URLSpan("http://www.google.com", 37, 41, 0));
tv.setText(text);

还有几种类型的其他 Span 对设置文本样式非常有用。 37 和 41 是要设置样式的文本的开始索引和结束索引。

还有 here是 Flavien Laurent 撰写的一篇关于 Spans 多种用途的优秀博客文章。

关于android - 获取链接信息android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22661705/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com