Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView ClickableSpan styling for pressed state [duplicate]

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

like image 352
dasony Avatar asked May 04 '12 09:05

dasony


1 Answers

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.

like image 53
Emanuele Fumagalli Avatar answered Nov 04 '22 17:11

Emanuele Fumagalli