示例代码如下,但正如您在图像中看到的,系统使用 jetpack compose Typography API(最后一个字符)提供的 roboto 字体比使用默认 Typography 配置的 roboto 字体(GenericFontFamily/第一个字符)。
Row {
MaterialTheme {
Column {
Box(
modifier = Modifier.border(
1.dp, color = Color.Black
)
) {
Text(
testText,
style = MaterialTheme.typography.headlineLarge.copy(
// fontSynthesis = FontSynthesis.None
),
maxLines = 1,
)
}
}
}
MaterialTheme(
typography = proximaTypography(),
) {
Column {
Box(
modifier = Modifier.border(
1.dp, color = Color.Black
)
) {
Text(
testText,
style = MaterialTheme.typography.headlineLarge.copy(
// fontSynthesis = FontSynthesis.None
),
maxLines = 1,
)
}
}
}
MaterialTheme(
typography = robotoTypography(),
) {
Column {
Box(
modifier = Modifier.border(
1.dp, color = Color.Black
)
) {
Text(
testText,
style = MaterialTheme.typography.headlineLarge.copy(
// fontSynthesis = FontSynthesis.None
),
maxLines = 1,
)
}
}
}
}
完整来源:
https://github.com/dazza5000/fontsforever/tree/master
注:
将 includeFontPadding 设置为 false 会导致更一致的渲染,如下所示
据我发现,这是由于字体填充造成的。在 jetpack compose Material 3 组件的未来版本中,默认情况下禁用字体填充
来源:
与此同时,我们可以使用以下方法手动禁用它
platformStyle = PlatformTextStyle(
includeFontPadding = false
),