使用字符串替换来更改URL链接的文本颜色

时间:2016-10-30 16:14:44

标签: java android string replace textcolor

我的意思是,是否可以将文字网址链接更改为单个字符串中的绿色?

例如,当我的字符串包含多个网址时,例如 示例。 (第1部分)是否可以设置" 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>

1 个答案:

答案 0 :(得分:0)

您可以看到this解决方案从HTML内容中启用TextView中的链接,并设置链接颜色,您可以在XML布局中设置android:textColorLink属性以指定链接&# 39;颜色。

如果只想将文本URL转换为链接,则不需要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/>