android – can I change the look and feel of the clickablespan-ThrowExceptions

Exception or error:

I have to embed a clickable text in a paragraph text, clickablespan can do it. But instead of using the default focus/press/unfocus style, can I change those style ? Like when focus, the background color is blue, text color is white, when unfocus, the background color is white, text color is blue.

How to solve:

Here is the example

bottomMsg = (TextView) findViewById(;
int start = bottomMsg.getText().toString().indexOf(terms);
MovementMethod movementMethod = LinkMovementMethod.getInstance();

Spannable text = (Spannable) bottomMsg.getText();
//TermAndConditions is a clickableSpan.
text.setSpan(new TermAndConditions(), start, start + terms.length(), Spannable.SPAN_POINT_MARK);
text.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.customYellowColor)), start, start + terms.length(), 0);

The point is, color-span is after the clickable-span. otherwise, the color not changed.


You can override the updateDrawState method of ClickableSpan:

SpannableString spannableString = new SpannableString("text");
    new ClickableSpan() {
        public void onClick(View widget) {
            Toast.makeText(getContext(), "Click!", Toast.LENGTH_LONG).show();

        public void updateDrawState(TextPaint ds) {
    }, 0, 4, Spanned.SPAN_INCLUSIVE_INCLUSIVE);




Link color can be changed in xml:

    android:textColorLink="..." />

Leave a Reply

Your email address will not be published. Required fields are marked *