如何在 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)
)
您需要创建自定义 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
)
)