is this possible to enable/disable backstack of particular item in bottom navigation view?

378 Views Asked by At

here is my bottom navigation controller setup

 fun setUpBottomNavigation(){
        nav_host_fragment=supportFragmentManager.findFragmentById(R.id.frag_container) as NavHostFragment
        nav_controller=nav_host_fragment.navController
        setUpActionBarConfiguration(nav_controller)
                  // manual handling of fragments aaa
        binding!!.bottomNavView.setupWithNavController(nav_controller)



    }
1

There are 1 best solutions below

0
Mert On

So, i think you are searching for this:

nav_host_fragment=supportFragmentManager.findFragmentById(R.id.frag_container) as NavHostFragment
     nav_controller=nav_host_fragment.navController
     setUpActionBarConfiguration(nav_controller)
     binding!!.bottomNavView.setupWithNavController(nav_controller)
     binding!!.bottomNavView.setOnItemSelectedListener { menuItem ->
//select your particular menuitem to apply backtrack deletion.
//if you remove if condition it, applies to all bottom menu items.
       if(menuItem.itemId == R.id.dashboard) {
       NavigationUI.onNavDestinationSelected(menuItem,nav_controller)
       nav_controller.popBackStack(menuItem.itemId, inclusive = false)
       }
            
     true
     }