Multiple spannableString.setSpan in a loop

111 views Asked by At

I'm creating a calculator app using Kotlin. I want to highlight the operation characters (+, -, *, /) by making their color blue. The array operationsInStrings is filled with indexes of characters from string that I wish to change the color to blue. Only the last member of the array turns to blue color Emulator screenshot. I tried using both spannableString and SpannableStringBuilder, but I'm probably doing something wrong as I'm new to the language. The array is filled correctly, as I tested it. Function code

1

There are 1 answers

0
j__m On

A single span can only have one location within a SpannableString or SpannableStringBuilder. To color multiple ranges, you need to create a different span for each range.