如何在 Jetpack compose 中为特定文本字段使用字体 Inter 样式

问题描述 投票:0回答:1

如何在 Jetpack compose 中使用 Inter style 字体:

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)
)
text android-jetpack-compose textstyle
1个回答
0
投票

您需要创建自定义 FontFamily 来覆盖默认系统 FontFamily。

将您的字体放入“res/font”文件夹中,然后您就可以如下所示使用它们。

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
    )
)
© www.soinside.com 2019 - 2024. All rights reserved.