Home > Mobile >  What dose FontFamily mean in Android Jetpack Compose?
What dose FontFamily mean in Android Jetpack Compose?

Time:12-05

Hello? I'm learning android Jetpack Compose with Google Jetpack Compose Pathway, and I have a question about FontFamily.

I saw a code using FontFamily like below.

private val Montserrat = FontFamily(
    Font(R.font.montserrat_regular),
    Font(R.font.montserrat_medium, FontWeight.W500),
    Font(R.font.montserrat_semibold, FontWeight.W600)
)

And I did an experience. I leave a Font object and remove others like below. And I found that App does not report compile error or runtime error and Some Style attribute like 'italic` is still applied to text.

private val Montserrat = FontFamily(
    Font(R.font.montserrat_regular)
)

So, I thought that Font objects in FontFamily will be used if they are more suitable to attributes specified in TextStyle.

Is my guess correct?

(Sorry for my english)

CodePudding user response:

A font family can have one or more fonts. When you set font weight & style in your texts, the closest style & weight is used.

For the italic style, it's probably done automatically by Compose instead of using a specific font when an italic font is not provided.

So for the more fonts you provide in your font family, the better the final result looks like.

  • Related