TextView ClickableSpan styling for pressed state [

2019-03-18 06:53发布

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

1条回答
走好不送
2楼-- · 2019-03-18 07:38

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.

查看更多
登录 后发表回答