gpt4 book ai didi

android - 使用 linkify 创建链接

转载 作者:太空狗 更新时间:2023-10-29 15:14:26 24 4
gpt4 key购买 nike

我想用一个简单的 html 字符串创建 linkify,例如“Search stackoverflow with Google”。已尝试使用正则表达式通过以下代码检测文本部分,但“stackoverflow”一词未在 TextView 上显示为链接

String content = "Search <b>stackoverflow<b> with Google";    
TextView tv = (TextView)this.findViewById(R.id.tv);
tv.setText(Html.fromHtml(content));
Pattern pattern = Pattern.compile("<b\b[^>]*>(.*?)</b>");
Linkify.addLinks(tvContent, pattern, "http://www.google.com/search?q=",
null, myTransformFilter);

如有任何帮助,我们将不胜感激。非常感谢....

最佳答案

你也许可以使用 Html.fromHtml()以获得您正在寻找的效果。

我认为像这样的东西可以做到:

tv.setText(Html.fromHtml("<a href=\"http://www.google.com/search?q=\">Search content with Google</a>");

注意:我没有编译这个,不确定我的转义是否正确,但你应该能明白这一点。

关于android - 使用 linkify 创建链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13898419/

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