Search code examples
javaandroidkotlinbottomnavigationviewandroid-jetpack-navigation

NavigationComponent with BottomNavigationView item selection


I'm using NavigationComponent with BottomNavigationView.

When i using navigation like that (A->B->B1) bottom navigation automatically change his selected item from A to B. I'm using default method for navigation.

findNavController().navigate(R.id.action_A_to_B) 

Then in fragment B i use again

findNavController().navigate(R.id.action_B_to_B1)

Only in this way I get the desired result.

When i tried to use navigation like that (A->B1) my bottom navigation don't change his selection from A to B.

findNavController().navigate(R.id.action_A_to_B1)

Schema of behaviour


Solution

  • When navigating, you can change the selection programmatically by this statement:

    bottomNavigation.selectedItemId=R.id.itemFragmentB