I want to change color of parts of a text several times with a timer.
Simplest way is this:
SpannableStringBuilder ssb = new SpannableStringBuilder(mainText);
ForegroundColorSpan span = new ForegroundColorSpan(Color.BLUE);
ssb.setSpan(span, start, end, 0);
tv.setText(ssb);
But if I run the above code several times in a second, I actually change the whole (large) text of TextView
each time so a unwanted memory-CPU load will happen specifically on lower-end devices.
How can I have a single Span
on TextView
and only change the Span
start and end position?
Will it work at all or a full text replace will happen behind the scene?
My text is fixed and won't change never.