I have the following code to set a color span on multiple subStrings of the same string.
fun getColoredText(text: String, @ColorInt color: Int, vararg coloredSubText: String): Spannable {
val spannable = SpannableString(text)
for (textToColor in coloredSubText) {
val start = text.indexOf(textToColor)
spannable.setSpan(
ForegroundColorSpan(color),
start,
start + textToColor.length - 1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
spannable.
}
return spannable
}
I provide the following arguments:
getColoredText("This is my full length of the string", someColorValue, "my", "length")
But everything after "my full length of the string"
gets colored.
Could someone please help figure out what is wrong with the above method?
thanks