TextView ClickableSpan styling for pressed state [duplicate]

拈花ヽ惹草 提交于 2020-01-22 10:43:10

问题


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:


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.



来源:https://stackoverflow.com/questions/10446079/textview-clickablespan-styling-for-pressed-state

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!