我们如何在 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));
我已经尝试了一些类似上面的代码,但它是用于在浏览器中打开的,我还想要像下图这样的东西
最佳答案
这可以使用 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/