0

What I mean is, is it possible to change the text URL link to the color green in a single string?

For example when I have a string which includes muliple URLs like below example. (Part 1) is it possible to set the text color of "http://information.com/qokp076wulpw" to green using string replace so it gets like in Part2?

Part 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>

Part 2:

<a class="postlink" href="http://information.com/qokp076wulpw"><font color='#1AB053'>http://information.com/qokp076wulpw</font><br/></a>
Simon
  • 1,691
  • 2
  • 13
  • 28

1 Answers1

0

You can see this solution to enable links in a TextView from a HTML content and, to set link colors you could set the android:textColorLink attribute in XML layout to specify the links' color.

If you want only convert text URLs to links, is not necessary Java code. You can simply add this in your 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/>
Community
  • 1
  • 1
dsdebastiani
  • 123
  • 4
  • Hi dsdebastiani, that`s not what I am looking for, the complete String is indeed loaded into a CustomeTextView but not all the URL links need to be colored green only certain ones, the rest of the links should stay normal color. That why I am trying to achieve this with string replce and then inject "" in the nessecary places to get the color green for that specific URL. – Simon Oct 30 '16 at 16:35
  • So you could use ```SpannableString``` to do that. This solution can help you: http://stackoverflow.com/a/7364716/3851246 – dsdebastiani Oct 30 '16 at 16:54
  • Not gonna work as have a function "setTextFromHtml" which cannot be used for this solution. I have a CustomTextView. My function. public void setTextFromHtml(String text) { this.setText(Html.fromHtml(Utils.parseSmiles(trim(text)))); this.setMovementMethod(LinkMovementMethod.getInstance()); } I need to set the text as holder.text.setTextFromHtml(item); – Simon Oct 30 '16 at 17:06
  • http://stackoverflow.com/questions/7364119/how-to-use-spannablestring-with-regex-in-android/7364716#7364716 works! I needed to change some code but it works. many thx! – Simon Oct 30 '16 at 17:26