is Spannable text customizable? Android

吃可爱长大的小学妹 提交于 2019-12-08 08:42:56

问题


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

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!

So, my question is:

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

Thanks


回答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.




回答2:


Have you tried using updateDrawState()?



来源:https://stackoverflow.com/questions/11544732/is-spannable-text-customizable-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!