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.