You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除Jetpack Compose中文本的字体内边距?

如何移除Jetpack Compose中文本的字体内边距?

我正尝试移除Jetpack Compose中文本顶部和底部的字体内边距,试过官方分享的解决方案但没有效果。

问题截图如下:
字体内边距问题

左侧(蓝色)是用Image组件渲染的图片,无内边距;右侧(灰色)是显示汉字“木”的Text组件,字符上下存在明显的字体内边距。

我使用的代码如下:

characters?.let {
    Text(
        text = it,
        style = MaterialTheme.typography.labelLarge.copy(
            color = color,
            fontFamily = notoSansJPFamily,
            fontSize = 72.sp,
            fontWeight = FontWeight.Normal,
            lineHeight = 72.sp,
            lineHeightStyle = LineHeightStyle(
                alignment = LineHeightStyle.Alignment.Center,
                trim = LineHeightStyle.Trim.Both
            ),
            platformStyle = PlatformTextStyle(
                includeFontPadding = false
            ),
        )
    )
} ?: CharacterIcon(
    resourceName = slug.resourceName(id),
    color = MaterialTheme.colorScheme.inverseSurface,
    fontSize = 72.sp,
)

CharacterIcon是自定义组件,当characters为null时会渲染图片(Image)。

请问该如何彻底移除这个字体内边距?


内容的提问来源于stack exchange,提问作者codejockie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 20:24:53