是Spannable文字定制? Android的(is Spannable text custo

2019-09-19 17:31发布

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文本颜色的!

所以,我的问题是:

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

谢谢

Answer 1:

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



Answer 2:

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



文章来源: is Spannable text customizable? Android