ReplacementSpan's draw() method isn't called

后端 未结 7 1969
北海茫月
北海茫月 2021-02-08 03:26

I set background in string like that:

spanString.setSpan(new BackgroundColorSpan(color), 0, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

But I would l

7条回答
  •  闹比i
    闹比i (楼主)
    2021-02-08 04:05

    Looks like I found a working (but hacky) solution to this problem. Try to add another symbol to the end of the string so that it isn't included in the span - and then draw() gets called!

     char EXTRA_SPACE = ' ';
     String text = originalString + EXTRA_SPACE;
     Spannable spannable = new SpannableString(text);
     spannable.setSpan(new MyReplacementSpan(), 0, text.length()-1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
     textView.setText(spannable);
    

    Looks like it ignores the spans which are whole string wide.

提交回复
热议问题