I am trying to get a string in a TextView which should look like this:
BOLD not bold BOLD not bold
I have tried this code:
val builder = SpannableStringBuilder()
val boldSpan = StyleSpan(Typeface.BOLD)
val spanFlag = Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
builder.append("BOLD ", boldSpan, spanFlag)
builder.append("not bold ")
builder.append("BOLD ", boldSpan, spanFlag)
builder.append("not bold ")
return builder
The problem is it's only bolding the last part. Result looks like this:
BOLD not bold BOLD not bold
Is there any way to bold multiple parts using a SpannableStringBuilder?