Spans for Kotlin made easier, plain and simple.
There are 3 steps to start using this library:
- you need to call the styleString method
- which will return the styled string that you can set on your TextView.
- decide which locator(s) fits your needs
- (optional) you can pass down a flag to override the default spanFlag for all styles on this locator
- pass down styles to each locator
- If using link or clickable you need to set movement method on your view
your_text_view.movementMethod = LinkMovementMethod()
- If using link or clickable you need to set movement method on your view
spannedContent = styleString(R.string.your_string_resource) {}
or, if you don't have a String resource just pass the string
spannedContent = styleString("Your string") {}
spannedContent = styleString(R.string.your_string_resource) {
all {
// Anything inside here applies to the whole content
}
firstAppearanceOf(R.string.what_ever_text_you_want_to_style) {
// Anything inside here applies to the first time the string appears inside the content
}
}
spannedContent = styleString(R.string.your_string_resource) {
all {
bold()
italic()
}
firstAppearanceOf(R.string.what_ever_text_you_want_to_style) {
absoluteSizeDP(24)
clickable {
// Do something when this is clicked
}
}
}
- EXCLUSIVE_EXCLUSIVE - (Default) anything added at the beginning or end of the section will NOT be modified by the styles on that section
- INCLUSIVE_INCLUSIVE - anything added at the beginning or end of the section will be modified by the styles on that section
- INCLUSIVE_EXCLUSIVE - anything added at the beginning will be modified by the styles on that section
- EXCLUSIVE_INCLUSIVE- anything added at the end of the section will be modified by the styles on that section
spannedContent = styleString(R.string.your_string_resource) {
all {
bold()
italic()
}
firstAppearanceOf(R.string.what_ever_text_you_want_to_style, spanFlag = EzFlags.INCLUSIVE_EXCLUSIVE) {
absoluteSizeDP(24)
clickable {
// Do something when this is clicked
}
}
}