I am subclassing ClickableSpan to customize the text style for links in my TextView.
private static class LinkSpan extends ClickableSpan {
@Override
public void onClick(View widget) {
// code...
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
ds.setTypeface(Typeface.create(ds.getTypeface(), Typeface.BOLD));
ds.setColor(0xff336699);
}
}
I want to change the style when it's in a pressed state, or a user touches the link. (like a:hover
in css) but I can't figure out a way to get the current state in updateDrawState
.
Is there any way to handle this? If I can't change text style, I want to be able to change the background color at least.
EDIT as pointed by a comment, you can find the answer at Change the text color of a single ClickableSpan when pressed without affecting other ClickableSpans in the same TextView
For changing background color I did
testTextView.setHighlightColor(Color.BLUE);
on the TextView.
But having the chance to change the text color would be better to me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With