Our font file has a default line height which is 1...
# compose-android
s
Our font file has a default line height which is 1.2 times the font size. For example, if the font size is 24px, the default line height would be 28.8px. According to the Figma design, the designer requires a line height of 24px matching the font size of 24px. In Android Compose, it's feasible to increase the line height from the default font specification but not reduce it.
works
- Setting Line Height larger than the default
Copy code
val Typography.Heading2: TextStyle
    get() = TextStyle(
        fontFamily = FontFamily.Default,
        fontWeight = FontWeight.Bold,
        fontSize = 24.sp,
        lineHeight = 30.sp, // Default line height - 24*1.2 = 28.8
        letterSpacing = 0.48.sp
    )
this doesn't work
- Setting Line Height smaller than the default
Copy code
val Typography.Heading2: TextStyle
    get() = TextStyle(
        fontFamily = FontFamily.Default,
        fontWeight = FontWeight.Bold,
        fontSize = 24.sp,
        lineHeight = 24.sp, // Default line height - 24*1.2 = 28.8
        letterSpacing = 0.48.sp
    )
Any idea how to set a smaller line height than the default line height?
m
These are your custom styles, right?
I can reduce the line by this. I think you can also extract this to a custom style.
Copy code
style = MaterialTheme.typography.labelLarge.copy(lineHeight = 8.sp)
s
yes, these are my custom styles with custom font. As I don't want to share the font file, I mentioned
FontFamily.Default
but the issue is not that
even as per your suggestion, line height 8.sp doesn't work as expected
you can see the issue in the attached screenshot. the line height doesn't reduce beyond the default line height specified in the font file
the Heading2CustomPreview is definitely not
8.sp
Any suggestions on this (either it is possible or not) would be appreciated