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

如何在启动页(Splash Screen)中隐藏底部导航栏

在Android Jetpack Compose启动页隐藏底部导航栏的解决方案

你可以通过路由判断控制底部导航栏的显示逻辑,仅在非启动页时渲染BottomAppBar,就能实现启动页隐藏底部导航栏的效果。修正后的完整代码如下:

Scaffold(
    bottomBar = {
        // 仅当前路由不是启动页时,显示底部导航栏
        if (currentRoute(navController) != Screen.SplashScreen.route) {
            BottomAppBar(
                modifier = modifier
                    .height(80.dp)
                    .padding(5.dp)
                    .clip(shape = RoundedCornerShape(60.dp)),
                containerColor = Color.Gray,
                tonalElevation = 5.dp
            ) {
                items.forEach { item ->
                    val selected = item.route == backStackEntry.value?.destination?.route
                    NavigationBarItem(
                        selected = item.route == navController.currentDestination?.route,
                        onClick = { onItemClick(item) },
                        icon = {
                            Column(horizontalAlignment = Alignment.CenterHorizontally) {
                                if (item.badgeCount > 0) {
                                    BadgedBox(badge = {
                                        Text(text = item.badgeCount.toString())
                                    }) {
                                        Icon(imageVector = item.icon, contentDescription = item.name)
                                    }
                                } else {
                                    Icon(imageVector = item.icon, contentDescription = item.name)
                                }

                                if (selected) {
                                    Text(text = item.name, textAlign = TextAlign.Center, fontSize = 10.sp)
                                }
                            }
                        },
                        colors = NavigationBarItemDefaults.colors(
                            selectedIconColor = Color.Green,
                            unselectedIconColor = Color.Red,
                            selectedTextColor = Color.Green,
                            indicatorColor = Color.DarkGray
                        )
                    )
                }
            }
        }
    }
) { innerPadding ->
    // 页面内容区域,使用innerPadding避免被底部导航栏遮挡
}

关键说明

  • 核心逻辑是通过currentRoute(navController)获取当前活跃页面的路由,与启动页Screen.SplashScreen.route做对比
  • 当路由不匹配启动页时,才会执行BottomAppBar的渲染代码,启动页自然不会显示底部导航栏
  • 注意保留Scaffold的content参数中的innerPadding,避免非启动页的内容被底部导航栏遮挡

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 20:20:18