1
String aux = getInserzionista(offerta.getIdInserzionista());

    sotto_titolo.setText("Offerta dal " + aux);

    int inizio = 12;
    int fine = 11+aux.length();

    sotto_titolo.setMovementMethod(LinkMovementMethod.getInstance());

    sotto_titolo.setText(sotto_titolo.getText().toString(),BufferType.SPANNABLE);

    Spannable mySpannable = (Spannable) sotto_titolo.getText();

    ClickableSpan myClickableSpan = new ClickableSpan() {
       @Override
       public void onClick(View widget) {

       }
    };

//if i put this, not work
mySpannable.setSpan(new ForegroundColorSpan(Color.RED), inizio, fine, 0);
mySpannable.setSpan(myClickableSpan, inizio, fine + 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

The result

But if i put this:

mySpannable.setSpan(new ForegroundColorSpan(Color.RED), 0, 4, 0);

It works, because the text from 0 to 4 is colored!

The result

So, my question is:

How can I change the color of the link (the one colored blue and underlined)?

Thanks

prolink007
  • 33,872
  • 24
  • 117
  • 185
Andrea
  • 57
  • 2
  • 8

2 Answers2

1

because you set a static value 4 in this line mySpannable.setSpan(new ForegroundColorSpan(Color.RED), 0, 4, 0);. Set text length in place of 4.

kalpana c
  • 2,739
  • 3
  • 27
  • 47
  • I've already solved :) the problem was the order of the instructions because this is right mySpannable.setSpan(myClickableSpan, inizio, fine + 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); mySpannable.setSpan(new ForegroundColorSpan(Color.RED), inizio, fine, 0); and not the previous... However thanks a lot – Andrea Oct 21 '12 at 09:45
0

Have you tried using updateDrawState()?

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141