Highlight on clickablespan click

Robert picture Robert · Apr 8, 2011 · Viewed 14.6k times · Source

I've got little problem, i need to remove or customize this orange highlight during clicking on clickablespan. This is my class extending ClickableSpan

public class InternalClickableSpan extends ClickableSpan {

    private String clicked;

    @Override
    public void updateDrawState(TextPaint ds) {
        ds.setUnderlineText(false);
    }

    public InternalClickableSpan(String clickedString) {
        clicked = clickedString;
    }

    @Override
    public void onClick(View view) {
        Selection.setSelection((Spannable) ((TextView)view).getText(), 0);
        Toast toast = Toast.makeText(mContext, clicked, Toast.LENGTH_SHORT);
        toast.show();
    }
}

and this is how i use it on text view

Spannable spans = (Spannable) tv.getText();      
spans.setSpan(new InternalClickableSpan(contacts[i]), text.indexOf(contacts[i]),   text.indexOf(contacts[i])+contacts[i].length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

Does anybody know how to customize "onclick highlight" on spannable object?

edit: Thanks Aleadam for response, i'am overriding updateDrawState (please take a look at the first method in my InternalClickableSpan class), but i can't find a way to customize this higlight anyway. Has anybody got other ideas? Thanks

Answer

hasanghaforian picture hasanghaforian · Oct 18, 2013

You can override onClick(View widget) like this:

        @Override
        public void onClick(View widget) {
            // do what must happen after click event.
            widget.invalidate();
        }