Skip to content

Semper-Viventem/RoundedBackgroundSpan

Repository files navigation

RoundedBackgroundSpan

It's simple implementation of background span with rounded corners for Android.

Usage

  1. Copy RoundedBackgroundColorSpan in your project.

  2. 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) } }
        }
    }