Java – when executing HTML Change the HTML link style in textviews after fromhtml

I'm developing an Android application I retrieve some data that looks like this:

<a href="http://google.com/" title=''><b><font color="gold">My Link to Google!</font></b></a>

I'm applying it to a textview like this:

myTextView.setText(Html.fromHtml(myHtmlString));

The problem I encountered here is HTML Fromhtml seems to apply a general style

Text example http://img30.imageshack.us/img30/2684/ss20110910171702.png

For any and all links, color them blue and underline them I'd rather not do that. Is there any simple solution to make it not stylized links (so I think "font color = whatever" will apply)? If the HTML link tag is inside the font / style tag, the behavior will not change

Solution

Use the Android: textcolorlink property I'm afraid this is the only way to change the link color

If you determine that there is only one link in the text, you can do the following:

Spanned text = Html.fromHtml(myHtmlString);
ForegroundColorSpan spans[] = text.getSpans(0,text.length(),ForegroundColorSpan.class);
if (spans.length > 0) {
    myTextView.setLinkTextColor(spans[0].getForegroundColor());
}
myTextView.setText(text);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>