UnderlineSpan already exists, but can only set the underline.
Another solution is to add a no underline span on each existing URLSpan. Thus the underline state is disabled just before painting. This way you keep your URLSpan (possibly custom) classes and all other styles set elsewhere.
public class NoUnderlineSpan extends UnderlineSpan {
public NoUnderlineSpan() {}
public NoUnderlineSpan(Parcel src) {}
@Override
public void updateDrawState(TextPaint ds) {
ds.setUnderlineText(false);
}
}
Here is how you set it without removing the existing URLSpan object:
URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
for (URLSpan span: spans) {
int start = s.getSpanStart(span);
int end = s.getSpanEnd(span);
NoUnderlineSpan noUnderline = new NoUnderlineSpan();
s.setSpan(noUnderline, start, end, 0);
}
answered 2013-06-11T11:36:33.433