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

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

我正在尝试这个:

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

就那么简单。

10-08 15:16