如何使用Android导航组件+ BottomNavigationView + NavigationView(导航抽屉) [英] How to use Android Navigation Component + BottomNavigationView+ NavigationView (Navigation Drawer)

本文介绍了如何使用Android导航组件+ BottomNavigationView + NavigationView(导航抽屉)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道使用导航组件+ BottomNavigationView + NavigationDrawer的最佳实践是什么.

I would like to know what is the best practice of using Navigation Component + BottomNavigationView + NavigationDrawer.

我已经尝试使用Google的导航组件高级示例 .对于多个后置堆栈模块,它的工作效果非常好.因为它具有

I have tried google's advanced sample for Navigation component. It worked very well for multiple back stack modules. Because it has a workaround extension. When using this approach, each bottom tab has its own graph and the graphs change as you select one of the tabs.

但是,当集成NavigationView时,它需要提前知道导航图.但是在高级示例中,没有使用navGraph属性,而是通过编程为bottomNavigation添加了图形.

But when NavigationView is integrated, it needs to know the navigation graph in advance. But in advanced sample the navGraph attribute is not used, graphs added programmatically for bottomNavigation.

当同时使用底部导航视图和导航抽屉视图时,我们如何管理图形?

So how do we manage graphs when both Bottom Navigation View and Navigation Drawer View are used together?

推荐答案

在尝试了不同的方法之后,我得出了结论,当同时使用BottomNavigationView和NavigationDrawer时,最好使导航图保持单一.当具有多个导航图时,将很难管理屏幕之间的逻辑连接.

After experimenting with different approaches, I have come to the conclusion, when using both BottomNavigationView and NavigationDrawer, It's best practice to keep your navigation graph single. When having multiple navigation graphs, it will be hard to manage logical connections between screen.

要控制工具栏和bottomNavigationView的可见性,我使用addOnDestinationChangedListener

To have a control over the toolbar and bottomNavigationView's visibility, I use addOnDestinationChangedListener

navController.addOnDestinationChangedListener { controller, destination, arguments ->
        when(destination.id){ //check with destination ids,  }

这可能不是最佳做法.如果您有更好的方法,请分享

it may not be best practice. If you have any better ways, please share it

这篇关于如何使用Android导航组件+ BottomNavigationView + NavigationView(导航抽屉)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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