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 issue I encounter here is that Html.fromHtml seems to apply a general styling
to any and 开发者_StackOverflow社区all links, which is to color them blue and underline them. I'd rather not have it do this, is there any simple solution to make it not stylize links(and therefore, I assume, "font color=whatever" would apply instead)? The behavior does not change if the HTML link tag is on the inside of font/style tags.
Use android:textColorLink
attribute. I'm afraid it's the only way to change link color.
If you're sure that you have only one link in the text then 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);
精彩评论