I want to give background color to the text that I receive from a List. At the moment I can get highlighted all the words, but I would like to exclude the spaces between the words
Initially I tried was to use a Pattern Matcher Regex solution so to exclude the double spaces, I was appending to the List. Then I realised that this solution was not the best because I could not exclude the spaces. So I decided to use a SpannableStringBuilder
and append the items inside a for loop. But does not work I get only the first word highlighted and not all the single words( separated by a blank(not coloured)word
val spannable = SpannableStringBuilder()
val span = BackgroundColorSpan(yellowColor))
listOfUsers.forEach {
val string = it.users
spannable.append(string)
spannable.setSpan(span, 0, string.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
}
textValue.text = spannable
I expect to see not only the first word, but the single words updated. Please notice that I am aware that the problem is in setSpan where I put as start 0 but I do no know how to make start working so to highlight the right initial string[I] character