在Jetpack Compose中使用textAppearance

3

我可以在Jetpack Compose中使用TextAppearance的内容吗?例如 textAppearanceHeadline1。如何实现呢?我想创建一个标题文本视图,但是我不想指定具体的dp值。所以我希望能够使用通常的textAppearanceHeadline1或类似的东西。


使用Text的style属性方式如下: Text(style = MaterialTheme.typography.h4) - Rajasekhar
1
谢谢,这正是我所寻找的。 - Mesye Konpe
1个回答

1

我想这可以帮助你。

@OptIn(ExperimentalUnitApi::class)
val textAppearanceHeadline1 = Typography(
    h1 = TextStyle(
        fontFamily = FontFamily.SansSerif,
        fontWeight = FontWeight.Light,
        fontStyle = FontStyle.Normal,
        fontSize = TextUnit(96f, TextUnitType.Sp),
        lineHeight = TextUnit(-0.015625f, TextUnitType.Unspecified),
    )
)

在你的文本中

Text(text = "Text", style = textAppearanceHeadline1.h1)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接