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

Jetpack Compose Material3主题Typography类型不匹配问题

解决Material3主题Typography类型不匹配问题

问题根源

Type.kt文件错误导入了kotlin.text.Typography,但Compose Material3的MaterialTheme组件要求传入的是androidx.compose.material3.Typography类型,两者不属于同一类,因此触发类型不匹配错误。

修复步骤

  • 打开Type.kt文件,检查顶部导入语句,若存在:
    import kotlin.text.Typography
    
    直接替换为:
    import androidx.compose.material3.Typography
    
  • 同步检查文件中TextStyle的导入,确保是Material3版本:
    import androidx.compose.material3.TextStyle
    
  • 确认模块级build.gradle.kts中已正确引入Material3依赖:
    dependencies {
        // 保留其他原有依赖
        implementation("androidx.compose.material3:material3:1.2.1") // 使用最新稳定版本即可
    }
    
  • 清理并重建项目:
    1. 点击Android Studio顶部菜单栏的Build -> Clean Project
    2. 完成后选择Build -> Rebuild Project

额外排查点

如果修复后仍报错,检查Theme.kt中传入MaterialTheme的typography参数,确认它是Type.kt中定义的Material3 Typography实例,而非其他来源的对象。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 17:24:51