I've mad a bit complex solution. I am replacing current URLSpan with custom one.
TextView textView = findViewById(R.id.textView);
// Make the link to be clickable
textView.setMovementMethod(LinkMovementMethod.getInstance());
// Url link
Spanned text = Html.fromHtml(getString(R.string.hello_there));
// We search for the first occurrence of URLSpanand we replace it with custom one
SpannableStringBuilder spannable = new SpannableStringBuilder(text);
Object[] spans = spannable.getSpans(0, spannable.length(), Object.class);
for (Object span : spans) {
if (span instanceof URLSpan) {
int spanStart = spannable.getSpanStart(span);
int spanEnd = spannable.getSpanEnd(span);
int spanFlags = spannable.getSpanFlags(span);
URLSpan spanUrlBase = (URLSpan) span;
MyUrlSpan myUrlSpan = new MyUrlSpan(spanUrlBase.getURL());
spannable.setSpan(myUrlSpan, spanStart, spanEnd, spanFlags);
break;
}
}
textView.setText(spannable);
--
private class MyUrlSpan extends URLSpan {
public MyUrlSpan(String url) {
super(url);
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setColor(Color.GREEN);
}
}
--
Xml doesn't recognize all special chars. I had to decode < to proper declaration.
<string name="hello_there"><a color="#8ABD37" href="tel:XXXXXXXXX">More info!</a></string>
More info here.