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);

结果

但如果我把这个:

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

它有效,因为从 0 到 4 的文本是彩色的!

结果

所以,我的问题是:

如何更改链接的颜色(蓝色和带下划线的颜色)?

谢谢

4

2 回答 2

1

因为您在这一行 mySpannable.setSpan(new ForegroundColorSpan(Color.RED), 0, 4, 0); 中设置了一个静态值 4。设置文本长度代替 4。

于 2012-10-16T07:23:03.733 回答
0

您是否尝试过使用 updateDrawState()?

于 2012-07-18T18:08:32.090 回答