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

Kotlin与Jetpack Compose中ExpandLess/ExpandMore引用未解决求助

解决Jetpack Compose中“Unresolved reference: ExpandLess/ExpandMore”错误
  • 检查Material图标依赖
    ExpandLess和ExpandMore属于Jetpack Compose的Material扩展图标库,需在模块级build.gradle.kts(或build.gradle)中添加对应依赖:

    // build.gradle.kts(Kotlin DSL)示例
    dependencies {
        implementation("androidx.compose.material:material-icons-extended:1.5.4")
        // 确保该版本与你项目中其他Compose依赖(如material、ui等)版本一致
    }
    

    替换1.5.4为你项目实际使用的Compose版本号,避免版本冲突导致依赖加载异常。

  • 添加正确的导入语句
    在使用图标的Compose函数文件顶部,导入对应图标类:

    import androidx.compose.material.icons.Icons
    import androidx.compose.material.icons.filled.ExpandLess
    import androidx.compose.material.icons.filled.ExpandMore
    

    若教程中使用的是其他风格图标(如Outlined、Rounded),需将filled替换为对应风格的包名。

  • 同步并重建项目
    添加依赖和导入后,点击Android Studio右上角的「Sync Project with Gradle Files」同步项目,再执行Build > Clean Project和Build > Rebuild Project,确保依赖完全加载。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 19:59:55