2012-07-18 22 views
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是Spannable文本可自定義? Android的

但是,如果我把這個:

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

它的作品,因爲從0到4文本顏色的!

The result

所以,我的問題是:

如何更改鏈接(在一個藍色帶下劃線)的顏色?

謝謝

回答

0

您是否嘗試過使用updateDrawState()?

+0

沒有函數updateDrawState(),類型ClickableSpan :( – Andrea 2012-07-19 08:33:47

1

因爲您在此行中設置了靜態值4 mySpannable.setSpan(new ForegroundColorSpan(Color.RED),0,4,0);.設置文本長度代替4.

+0

我已經解決了:)問題是指令的順序,因爲這是正確的mySpannable。 setSpan(myClickableSpan,inizio,fine + 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); mySpannable.setSpan(新的ForegroundColorSpan(Color.RED),inizio,很好,0);而不是以前...但非常感謝 – Andrea 2012-10-21 09:45:20

相關問題