1

I want to achieve something like this image flow in android navigation component. Where the Dashboard Fragment is the start destination. And from here i can navigate to another fragment which have a bottom navigation view. Is this possible using a single nav graph and a single activity? What is the best way to achieve something like this? bottom navigation view with android navigation component

EA Rashel
  • 167
  • 2
  • 9

2 Answers2

1

You can use BottomNavigationView

    val childNavView: BottomNavigationView = binding.nav1View
    val navController = NavHostFragment.findNavController(childFragmentManager.findFragmentById(R.id.navHostFragment) as NavHostFragment)
    childNavView.setupWithNavController(navController)
Zhming
  • 333
  • 3
  • 12
0

In case someone's still looking for a solution.

Just use two separate navigation graphs. And when navigating, pick the right navigation controller object. You can use a single activity of course, with nested fragments. So your "Bottom nav page" will have its own navigation container with child fragments in it.

Moreover, you can also navigate from the inner nodes to outer ones. In that case you need to reference the parent fragment ("Bottom nav page") from the child fragment and then obtain its navigation controller like this:

parentFragment?.parentFragment?.findNavController()

Here the first parentFragment is NavHostFragment and its parent is your actual parent fragment ("Bottom nav page").

davee44
  • 357
  • 3
  • 10