It's simple implementation of background span with rounded corners for Android.
-
Copy RoundedBackgroundColorSpan in your project.
-
Use it from your code:
private fun initSpannableText() {
val span = RoundedBackgroundColorSpan(
backgroundColor = colors.random(),
padding = dp(5),
radius = dp(5)
)
with(spanText) {
setShadowLayer(dp(10), 0f, 0f, 0) // it's important for padding working
text = buildSpannedString { inSpans(span) { append(str) } }
}
}