我在我的应用程序中有一个TextView,我想将文本显示为链接。
我有一个"查看地图"字符串,我想将其显示为超链接(蓝色和带下划线)。
我尝试了以下代码:
tvSeeMap.setText(getResources().getString(R.string.see_map));
Linkify.addLinks(tvSeeMap, Linkify.ALL);
但是它不起作用。
我在我的应用程序中有一个TextView,我想将文本显示为链接。
我有一个"查看地图"字符串,我想将其显示为超链接(蓝色和带下划线)。
我尝试了以下代码:
tvSeeMap.setText(getResources().getString(R.string.see_map));
Linkify.addLinks(tvSeeMap, Linkify.ALL);
但是它不起作用。
String tempString = new String(getResources().getString(R.string.see_map));
SpannableString content = new SpannableString(tempString);
content.setSpan(new UnderlineSpan(), 0, tempString.length(), 0);
tvSeeMap.setText(content);
tvSeeMap.setTextColor(getResources().getColor(R.color.blue));
使用
Linkify.addLinks(tvSeeMap,Linkify.WEB_URLS);
替代
Linkify.addLinks(tvSeeMap, Linkify.ALL);
如何在textView中显示超链接或网址链接
Linkify.ALL
是 0x0F,而 Linkify.WEB_URLS
是 0x01 - 这是您正在通过此更改解决的错误吗? - Marcin Orlowski链接是否有 "http://" 前缀?如果没有,请尝试添加它。或者可能是链接前后没有空格