Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set LineHeight using AnnotatedString in Jetpack Compose

I'm working right now with AnnotedStrings to create this Text with two different text styles: Image with alabel displaying 1.26 Kilowatts text

I'm setting up this label using a SpanStyle. How do I setup the line height this way? Because SpanStyle is missing this attribute.

like image 407
Felipe Castilhos Avatar asked Jun 12 '26 21:06

Felipe Castilhos


1 Answers

You can use the ParagraphStyle to define the lineHeight and the lineHeightStyle.

Something like:

buildAnnotatedString {
    withStyle(style = ParagraphStyle(lineHeight = 60.sp)) {
        withStyle(style = SpanStyle(color = Color.Blue, fontSize= 60.sp)) {
            append("Hello")
        }
        append("Compose")
    }
}

enter image description here

like image 171
Gabriele Mariotti Avatar answered Jun 15 '26 12:06

Gabriele Mariotti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!