4

我的应用中有 TextView,我想将文本显示为链接。

我有“查看地图”字符串,我想将其显示为超链接(蓝色和下划线)。

我正在尝试这个:

tvSeeMap.setText(getResources().getString(R.string.see_map));
    Linkify.addLinks(tvSeeMap, Linkify.ALL);

但它不会工作。

4

3 回答 3

5

我找到了解决方法

 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));

就那么简单。

于 2012-11-09T20:12:58.510 回答
2

采用

Linkify.addLinks(tvSeeMap,Linkify.WEB_URLS);

代替

Linkify.addLinks(tvSeeMap, Linkify.ALL);

在 textView 中显示超链接或 web url 作为链接

于 2012-11-09T19:30:37.440 回答
0

链接是否有“http://”前缀?如果没有,请尝试添加它。或者可能是链接前后没有空格

于 2012-11-09T19:27:25.733 回答