android - 获取链接信息android

标签 android

我们如何在 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/

相关文章:

java - 如何在单击按钮时在一个方法中执行 2 个操作

Android 在单击按钮时在自定义 ListView 中隐藏和显示复选框

android - 无法将 react-native 2 项目构建到手机

android - 安全过滤 CALL_PRIVILEGED

Android 和 JUnit : How to add individual tests to test suite?

android - 如何从 RecyclerView 获取从数据库中获取的列表项值?

javascript - 如何判断我的 PhoneGap JavaScript 应用程序当前是在 Android 还是 iOS 上运行?

android - "@android:drawable/ic_"与 "@*android:drawable/ic_"

android - 将 XMPP 与 .net 服务器和 android 客户端一起使用

android - 协调器布局中自定义 View 的 BringToFront