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

Android 15(targetSdk 35)导航栏与状态栏图标颜色修改问题

解决Android 15(targetSdk 35)Edge-to-Edge模式下状态栏/导航栏图标颜色适配问题

一、状态栏图标颜色修改(已验证方案)

你使用的rememberSystemUiController方案是Jetpack Compose下的标准实现,可根据页面背景动态切换图标明暗:

val systemUiController = rememberSystemUiController()
val isLightBackground = remember { mutableStateOf(true) } // 根据页面背景动态赋值

LaunchedEffect(isLightBackground) {
    systemUiController.setStatusBarColor(
        color = Color.Transparent,
        darkIcons = isLightBackground.value
    )
}

二、导航栏图标颜色修改方案

针对导航栏,同样通过rememberSystemUiController的setNavigationBarColor方法控制图标明暗,核心参数也是darkIcons:

LaunchedEffect(isLightBackground) {
    systemUiController.setNavigationBarColor(
        color = Color.Transparent,
        darkIcons = isLightBackground.value
    )
}

三、合并控制状态栏与导航栏

若需统一配置两类栏目的图标颜色,可将逻辑合并到同一个LaunchedEffect中:

val systemUiController = rememberSystemUiController()
val isLightBackground = remember { mutableStateOf(true) }

LaunchedEffect(isLightBackground) {
    // 状态栏配置
    systemUiController.setStatusBarColor(
        color = Color.Transparent,
        darkIcons = isLightBackground.value
    )
    // 导航栏配置
    systemUiController.setNavigationBarColor(
        color = Color.Transparent,
        darkIcons = isLightBackground.value
    )
}

注意事项

  • 确保Compose依赖版本不低于androidx.compose.ui:ui:1.6.0,避免API兼容问题
  • darkIcons取值需与页面背景反相:浅色背景设为true(深色图标),深色背景设为false(浅色图标)
  • 不同页面单独适配时,只需在对应页面的Composable中实现上述逻辑即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 01:22:10