How can I use font Inter style in Jetpack compose for specific Text field

40 views Asked by At

How can I use font Inter style in Jetpack compose:

Text(
  text = "",
  style = TextStyle(
        fontSize = 14.sp,
        lineHeight = 20.sp,
        fontFamily = FontFamily.Default,
        fontWeight = FontWeight(500),
        fontStyle = FontStyle.Inter, ///////Inter
        textAlign = TextAlign.Center,
        letterSpacing = 0.1.sp)
)
1

There are 1 answers

0
Hiren Rafaliya On

You need to create custom FontFamily for that which will override the default system FontFamily.

Place your fonts inside the 'res/font' folder, and then you can use them as shown below.

val interFontFamily = FontFamily(
    Font(R.font.inter_regular, style = FontWeight.Normal),
    Font(R.font.inter_italic, style = FontStyle.Italic),
    Font(R.font.inter_bold, style = FontWeight.Bold)
)

Text(
    text = "Your text here",
    style = TextStyle(
        fontSize = 14.sp,
        lineHeight = 20.sp,
        fontFamily = interFontFamily, // Using the Inter font family
        fontStyle = FontStyle.Normal,
        textAlign = TextAlign.Center,
        letterSpacing = 0.1.sp
    )
)