导航到可组合时,我们如何隐藏BottomAppBar(带导航包括)? [英] How can we hide BottomAppBar (with navigation include) when navigate to composable?

查看:78
本文介绍了导航到可组合时,我们如何隐藏BottomAppBar(带导航包括)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题.

问题是当我导航到添加问题"时,我不知道如何隐藏底部应用栏.屏幕.

The problem is that i don't know how to hide bottom app bar when i'm navigating to a "add question" screen.

我需要你的帮助.

这是带有底部应用栏的 MyScreen

This is MyScreen with the bottom app bar

@Composable
fun Navigation() {
    val navController = rememberNavController()
    val items = listOf(Screen.Home, Screen.Search, Screen.Notifications, Screen.Profil)

    Scaffold(
        bottomBar = {
            bottomAppNavigation(navController = navController, items)

        }
    ) {
        Box(modifier = Modifier.padding(it)) {
            ScreenController(navController = navController)
        }

    }
}

这是我的带有导航主机的控制器

And this is My controller with navHost

@ExperimentalComposeUiApi
@Composable
fun ScreenController(navController: NavHostController) {
    NavHost(navController = navController, startDestination = Screen.Home.route) {
        composable(Screen.Home.route) {
            HomeScreen(navController)
        }
        composable(Screen.Search.route) {
            SearchScreen(navController, it)
        }
        composable(Screen.Notifications.route) {

        }
        composable(Screen.Profil.route) {
            user_profil()
        }
        composable("Ask_question") {
            AskScreen(navController)
        }
    }
}

我认为的问题是因为这就像活动和片段,我有一个可组合屏幕所在的盒子,我所有的页面都在他里面.

The problem i think it's because that's like activity and fragment, i have a box where the composable screen goes, and all my pages are in him.

推荐答案

如果你想隐藏 BottomBar 就不要输出它.

If you want to hide the BottomBar just don't output it.

类似于:

Scaffold(
    bottomBar = {
        if (currentRoute != "xxxx") {
            BottomAppBar() {
               //....
            }
        }
    },

currentRoute 在哪里(至少使用 Navigation Compose 2.4.0-alpha01):

where the currentRoute is (using at least Navigation Compose 2.4.0-alpha01):

val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry.destination.route

这篇关于导航到可组合时,我们如何隐藏BottomAppBar(带导航包括)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆