how to prevent fontFamily from changing when system-font is changed in compose?

Viewed 28

I'm developing android with compose now. The Text widget is set by FontFamily.Default. My Galaxy 20 has several font families(Default, SamsungOne, Thick Gothic), and when I change them, the compose text FontFamily is also changed. I want to prevent this from changing. Is there any way about this?

1 Answers

It's easy. Set a font family using the fontFamily parameter.

Text(
    text = "I'm Roboto Font",
    fontSize = 22.sp,
    fontFamily = FontFamily(Font(R.font.roboto_medium, weight = FontWeight.Medium)),
    color = Color.DarkGray
)

You can downlod the fonts from the Google Fonts site. Put them in the res > font folder. Follow this guide.

Related