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

Android Studio入门遇Jetpack Compose Text组件参数错误求助

问题原因及修复方案

错误出在第二个Text组件的参数使用上:

  • 你误把设置字体大小的参数fontSize写成了fontStyle
  • fontStyle的作用是指定字体样式(比如斜体),它接受的是FontStyle枚举类型的值(比如FontStyle.Normal、FontStyle.Italic),而不是30.sp这种尺寸数值

修正后的代码如下:

@Composable
fun GreetingText(from: String, message: String, modifier: Modifier = Modifier) {
    Text(text = message, fontSize = 100.sp, lineHeight = 116.sp)
    Text(text = from, fontSize = 30.sp)
}

如果需要给from文本额外设置字体样式,可以补充fontStyle参数,示例:

Text(text = from, fontSize = 30.sp, fontStyle = FontStyle.Italic)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 18:12:01