I have an Android app that uses the navigation component, the app offers a multi-level drill down navigation mode (the hierarchy is dynamic, so there can be an arbitrary amount of levels). I am trying to put that navigation in a tab in a BottomNavigationView (and also adding others with the same navigation structure).
I setup the navigation view using binding.bottomNavigation.setupWithNavController(this.navHostFragment.navController). The BottomNavigationView uses the following menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/fragment_1"
android:title="@string/title_1" />
<item
android:id="@+id/fragment_2"
android:title="@string/title_2" />
</menu>
fragment_1 and fragment_2 are define in the navigation xml among other fragments that can be pushed into the navigation hierarchy. And both are defined as top level fragments using AppBarConfiguration.
The app launches fine, and the bottom tabs contain the expected content, but once I start navigating to other fragments (drill down), the current tab loses the current selection (because the id of the new fragment doesn't match the one set in the menu?), if I am on the second one the first one is selected in the bar but the content doesn't change.
What's the proper way of doing this? Is there any official approach? Do I need two NavHostFragment and swap them manually when the user changes from one of the bottom tabs to another one?