Most efficient way for Dynamic Text Color Change in TextView

后端 未结 3 1408
情话喂你
情话喂你 2020-12-17 02:42

I want to change color of parts of a text several times with a timer.

Simplest way is this:

SpannableStringBuilder ssb = new SpannableStringBuilder(m         


        
3条回答
  •  情书的邮戳
    2020-12-17 03:36

    I meet the same issue this afternoon,and here is my solution:

    tv.setText(yourText, TextView.BufferType.SPANNABLE);
    ForegroundColorSpan span = new ForegroundColorSpan(Color.BLUE);
    ((Spannable) article.getText()).setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    

    I found it's a much more efficient way,in my project I used set-whole-text method took 400~600 milliseconds,by this way only 0 or 1 millisecond.

提交回复
热议问题