문제

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

Text example

to any and 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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top