Android 带有嵌套底部导航的导航

Android Navigation with nested bottom navigation

我是 Android 导航组件的新手,想了解如何在我想要使用单一 activity 方法的相对简单的场景中使用它。我显然希望系统处理返回堆栈,也用于底部导航。

我需要的是2个很简单的案例:

1。混合目的地

我的导航图中有些目的地有底部导航,有些则没有。想象一下,我有一个没有底部导航的登录流程,然后移动到我有底部导航的 "real app" 。 Google 表示将底部导航、抽屉、操作栏放在导航图之外,这意味着它们会在所有目的地显示。

导航组件支持吗?没有 hiding/showing 底部导航的肮脏黑客。

2。全屏弹出窗口

另一个问题 - 是否支持多个导航主机?假设我有一个带有底部导航和操作栏的 UI,它们位于导航宿主区域之外。但随后我需要显示一个全屏弹出窗口,例如对话框或资源选择屏幕,它也会覆盖底部导航栏和操作栏。

我可以将此作为导航图中的目的地吗?


对于这两个问题,任何概念上支持的解决方案都适合我,包括在导航期间切换 graphs/hosts。

根据 Listen for navigation events documentation:

As an example, you might have common UI elements that you intend to show in some areas of your app while hiding them in others. Using your own OnDestinationChangedListener, you can selectively show or hide these UI elements based on the target destination

是的,当您移动到某些目的地(例如登录屏幕)时,您可以有选择地显示或隐藏 activity 的 UI 元素。

根据 Create a destination from a DialogFragment documentation:

If you have an existing DialogFragment, you can use the <dialog> element to add the dialog to your navigation graph

这也支持其他类型的 DialogFragment,例如 BottomSheetDialogFragment