Android导航组件+登录流程+嵌套BottomNavigationView [英] Android Navigation Component + Login Flow + Nested BottomNavigationView
问题描述
我正在努力用Android导航组件构建一个导航,如下图所示。
I'm struggle building a Navigation, like on the image below, with the Android Navigation Component.
我需要一个登录流程,检查用户是否已登录,然后导航到应用程序的主要部分(还清除了堆栈)。主要部分包含一个带有三个选项卡的BottomNavigationView。但是,如果我单击工具栏上的设置图标,我还想显示全屏的SettingsFragment。
I need a "Login Flow", check if the user is logged in and then navigate to the main part of the app (also clearing the backstack). The main part contains a BottomNavigationView with three tabs. But if I click on a settings icon on the toolbar, I also want to display a fullscreen SettingsFragment.
我是否需要两个带有单独导航图的NavHostFragments?如果是,我如何将它们结合起来并拥有适当的backNavigation?
Did I need two NavHostFragments with separate navigation graphs? If yes, how can I combine them and also have a proper backNavigation?
有什么想法可以通过android导航组件实现这种导航吗?
Any ideas how realize a navigation like this with the android navigation components?
推荐答案
首先,您可以检查条件导航
第二,您只需一个 nav_graph
即可完成。但是您只需要一个 Activity
即可。之后,您可以像这样检查它:
Second of all, you can do it with only one nav_graph
. But you need only one Activity
for this. After that, you can check in it like this:
navController.addOnDestinationChangedListener { _, destination, _ ->
if(destination.id == R.id.mainFragment){
if(userIsLoggedIn()){
//start LoginFragment
//hide bottom navigation
}else{
//show bottom navigation
}
}
}
但是您的入门片段应该是 MainFragment
而不是 LoginFragment
But your starter fragment should be MainFragment
and not LoginFragment
这篇关于Android导航组件+登录流程+嵌套BottomNavigationView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!