1

I have a TextView which has the following text:

This is an example site.

I'm trying the text decoration attribute. I want to remove the underline from the hyperlink and I want to change the color of the hyperlink. Here's my code:

String string = "This is an "
            + "<a href=\"http://www.example.com\" 
                  style=\"text-decoration:none; color: #0000ff\">"
            + example
            + "</a>"
            + " site."

Spannable text = (Spannable)Html.fromHtml(string);

textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setText(text);

The links are not underlined now, still clickable, but grey in color. Is the color attribute not allowed in Html.fromHtml? Is there a way I could achieve it using the HTML tags? (All I want is removing the underline and changing the color of a substring of my TextView).

UPDATE:

Did android:textColorLink="@color/colorPrimary" in the xml of the TextView and the link color changed to the required color. Though still not sure why would normally using the color attribute won't work here.

Akeshwar Jha
  • 4,516
  • 8
  • 52
  • 91
  • http://stackoverflow.com/questions/4096851/remove-underline-from-links-in-textview-android Please have a look – Crazy Engineer Jun 09 '16 at 09:28
  • OR http://stackoverflow.com/questions/8448390/how-to-remove-underline-from-hyperlinks-text-in-android -------- https://prativas.wordpress.com/category/android/textview-hyperlink-change-color-and-remove-underline/ – Crazy Engineer Jun 09 '16 at 09:29
  • @CrazyEngineer, I'm concerned about why is the color attribute not working. Alternate solutions using java methods - I've already checked them out. – Akeshwar Jha Jun 09 '16 at 09:31
  • yourText.setLinkTextColor(Color.ChooseColor); – Crazy Engineer Jun 09 '16 at 09:33

0 Answers0