Tuesday, 19 October 2021

Add small padding/margin between text with AnnotatedString

Whenever I use the buildAnnotatedString I must write some sort of style using ParagraphStyle or SpanStlye. Sadly none of these 2 classes have modifiers to add some padding between every text (append)

This is what I'm getting right now. There should a small space between the background and the letters at the start and at the end of every text:

enter image description here

This is the code with the background:

val spanStyle = (
    MaterialTheme.typography.body1.copy(
     color = MaterialTheme.colors.onSurface,
     fontWeight = FontWeight.W400,
     fontSize = 17.sp,
     letterSpacing = 0.25.sp,
     background = MaterialTheme.colors.surface,
     baselineShift = BaselineShift(0.2f),
)).toSpanStyle()

buildAnnotatedString {
    withStyle(style = spanStyle) {
         append("I write text here with background")
    }
}

I've checked ParagraphStyle but the only thing related to vertical space is the lineHeight which obviously increase the height of every line but not the space between them.

Is there any way to add this little small space between every append() so background isn't coupled?



from Add small padding/margin between text with AnnotatedString

No comments:

Post a Comment