shihpeng
shihpeng

Reputation: 5381

How to change the foreground/background colors of a link in a TextView?

I need to put some links in one TextView. For better user experience, I would like to highlight the links when user click by changing the foreground/background colors of the links.

I have tried android:textColorLink and TextView.setLinkTextColor(ColorStateList), but none of both works.

Any idea?

Upvotes: 1

Views: 1618

Answers (1)

Gorets
Gorets

Reputation: 2442

I think a best way is using Spannable

Spannable sps=(Spannable )tv.getText();
sps.setSpan(new BackgroundColorSpan(Color.YELLOW), start, end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

Upvotes: 1

Related Questions