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

Compose中三星Galaxy 20导航栏颜色设置失效问题

三星Galaxy 20设备导航栏透明配置失效问题

问题现象

仅在三星Galaxy 20物理设备上出现系统导航栏透明设置异常,所有Android Studio模拟器(Pixel 4/5/6)表现正常:

  • 应用内自定义NavigationBar组件可见时,其下方的系统导航栏区域为透明,未继承自定义NavigationBar的colorScheme.surfaceColorAtElevation(3.dp)颜色
  • 无自定义NavigationBar的页面,系统导航栏也未继承页面surface颜色
  • 若将系统导航栏颜色固定为colorScheme.surfaceColorAtElevation(3.dp),则所有页面均保持该颜色,不符合需求

当前配置代码

themes.xml

<style name="Theme.App" parent="Theme.Material3.DayNight.NoActionBar" >
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:navigationBarColor">@android:color/transparent</item>
    <item name="android:windowBackground">?attr/colorSurface</item>
</style>

主Activity代码

WindowCompat.setDecorFitsSystemWindows(window, false)

Theme.kt代码

@Composable
fun AppTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    content: @Composable () -> Unit
) {
val colorScheme = when {
    darkTheme -> DarkColorScheme
    else -> LightColorScheme
}

val systemUiController = rememberSystemUiController()
DisposableEffect(systemUiController, darkTheme) {
    systemUiController.setSystemBarsColor(
        color = Color.Transparent,
        darkIcons = !darkTheme
    )
    onDispose { }
}

MaterialTheme(
    colorScheme = colorScheme,
    typography = Typography,
    content = content
)
}

解决方案建议

  1. 检查设备系统设置:三星One UI部分版本有"导航栏透明度"或"全屏手势"相关系统设置,可能覆盖应用配置,需确认设备是否开启此类设置并调整
  2. 添加三星适配属性:在themes.xml中添加以下属性,禁用导航栏强制对比度,避免系统覆盖透明设置:
    <item name="android:enforceNavigationBarContrast">false</item>
    <item name="android:navigationBarContrastEnforced">false</item>
    
  3. 页面级动态设置导航栏颜色:不在全局AppTheme中统一设置透明,而是在每个页面根据是否显示自定义NavigationBar调整:
    • 显示自定义NavigationBar的页面:调用systemUiController.setSystemBarsColor(color = colorScheme.surfaceColorAtElevation(3.dp), darkIcons = !darkTheme)
    • 不显示的页面:调用systemUiController.setSystemBarsColor(color = Color.Transparent, darkIcons = !darkTheme)(或页面对应的surface颜色)
  4. 调整布局Insets处理:让自定义NavigationBar延伸到系统导航栏区域,视觉上实现颜色统一,示例代码:
    Box(
        modifier = Modifier.fillMaxSize()
    ) {
        // 页面内容区域
        CustomNavigationBar(
            modifier = Modifier
                .align(Alignment.BottomCenter)
                .navigationBarsPadding(bottom = false) // 允许组件覆盖系统导航栏区域
        )
    }
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 10:17:12