15

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

Community
  • 1
  • 1
dasony
  • 3,708
  • 2
  • 22
  • 20

1 Answers1

9

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.

Parag Chauhan
  • 35,760
  • 13
  • 86
  • 95
Emanuele Fumagalli
  • 1,476
  • 2
  • 19
  • 31
  • This was not what I asked, but I accepted this answer since it's the only answer. The real solution is at http://stackoverflow.com/a/20905824/1646326 – dasony Jul 29 '14 at 08:14
  • Next time don't be shy to post the link in an actual answer and mark that as correct. It will help others by making the answer more visible. – Alexandre G Jan 27 '15 at 01:02
  • 1
    @dasony if this is not the answer the there is no point in marking it as such. I guess it would be more helpful for you to edit your question to point people to that link, in case you don't want to post your own link answer. – Leo supports Monica Cellio May 19 '15 at 18:03