Android compose font line height not work

48 views Asked by At

I'm developing an Android app with Jetpack Compose.

Since it's a globally serviced app, it supports multiple languages (English and Chinese). Due to differences in characters, designer wants to use different fonts for each language.

So, we're applying separate font files for English and Chinese.

  • res/font/bold.otf
  • res/font/regular.otf
  • res/font-zh/bold.ttf
  • res/font-zh/regular.ttf
internal val fontFamily = FontFamily(
    Font(resId = R.font.bold, weight = FontWeight.Bold, style = FontStyle.Normal),
    Font(resId = R.font.regular, weight = FontWeight.Normal, style = FontStyle.Normal),
)

val subhead = TextStyle(
    fontFamily = fontFamily,
    fontSize = 16.sp,
    lineHeight = 24.sp
)

I defined like upper codes and used it in my Text:

Text(
    text = title,
    modifier = Modifier.background(Blue200),
    style = SpoonTheme.typo.subhead
)

But the result is weird. Below is English version: enter image description here

And below is Chinese version: enter image description here

Font size and line height are the same, only the font files differ based on language settings.

I assumed that applying line height would adjust the size accordingly, but is the line height being ignored to follow the font file?

Is there a way to ignore the font file's padding and force it to follow the line height?

1

There are 1 answers

0
Chirag Thummar On

You can try removing the padding from the text using

Text(
...
   style = TextStyle(
      platformStyle = PlatformTextStyle(
     includeFontPadding = false
   ),
)