CustomSpanString is a class which you can use for applying multiple spans in single textview the spans you can use for Bold, Underline, Color and Clickable
val greeting = "Hello"
val name = "SpannableString"
// Important: Set final text in textView before using CustomSpanStrings
val title = "$greeting, $name"
textView.text = title
CustomSpanStrings.withTextView(textView)
.addClickListener(name) {
// Do something when $name is clicked
}
.applyBold(name) // To apply bold to $name
.applyUnderline(name) // To apply underline to $name
.applyColor(Color.GRAY, name) // To change color of $name
.applyColor(Color.LTGRAY, greeting) // To change color of $greeting
.commit() // Finally commit all changes
To initialize SpannableStringBuilder using the text from textView
CustomSpanStrings.withTextView(textView)
To add click listener to $name text.
.addClickListener(name) {
// Do something when $name is clicked
}
To apply bold to $name text. You can pass multiple texts to apply bold effect to the texts.
.applyBold(name)
To apply underline to $name text. You can pass multiple texts to apply underline effect to the texts.
.applyUnderline(name)
To apply grey color to $name text. You can pass multiple texts to apply same color to the texts.
.applyColor(Color.GRAY, name)
For applying all spans and set to your textview
.commit()