使用字符串替换更改 URL link 的文本颜色

Use string replace to change text color of URL link

我的意思是,是否可以在单个字符串中将 text URL link 更改为绿色?

例如,当我有一个包含多个 URL 的字符串时,例如 下面的 示例。 (第 1 部分)是否可以使用 string replace 将“http://information.com/qokp076wulpw”的文本颜色设置为绿色,使其与第 2 部分中的一样?

第 1 部分:

<a class="postlink" href="http://test.site/i7xt1.htm">http://test.site/i7xt1.htm<br/></a><br/>Mirror:<br/><a class="postlink" href="http://information.com/qokp076wulpw">http://information.com/qokp076wulpw<br/></a>

第 2 部分:

<a class="postlink" href="http://information.com/qokp076wulpw"><font color='#1AB053'>http://information.com/qokp076wulpw</font><br/></a>

您可以查看 this 解决方案以在 TextView 中启用 HTML 内容中的 links,并设置 link 颜色,您可以设置XML 布局中的 android:textColorLink 属性指定 link 的颜色。

如果您只想将文本 URL 转换为 links,则不需要 Java 代码。您可以简单地将其添加到您的 TextView 中:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/txt_no_html_tags"
    android:textColorLink="#00FF00"
    android:autoLink="web"
    android:linksClickable="true/>