I'm trying to replace a certain string with a span.
For example I have this String:
String s = "redHello greenWorld";
I wanna replace "red" with:
modifiedText.setSpan(new ForegroundColorSpan(Color.parseColor("#FF0000")), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
and "green" with:
modifiedText.setSpan(new ForegroundColorSpan(Color.parseColor("#00FF00")), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
So I create modifiedText this way:
Spannable modifiedText = new SpannableString(s);
How can I replace a certain String with a Span without HTML?
Since you asked about cutting out - I hope this is what you meant (new code)
Now you need to sort the list
And subtract the "red" and "green"
The end result now contains [0, 6, 12], the starting indexes of the spans - now you only need to iterate through the output and set the spans (the colors to the spans are in
sorted_color
)