NavigationComponent with BottomNavigationView 项目选择

NavigationComponent with BottomNavigationView item selection

我将 NavigationComponent 与 BottomNavigationView 一起使用。

当我使用这样的导航时 (A->B->B1),底部导航会自动将他选择的项目从 A 更改为 B。 我正在使用默认方法进行导航。

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

然后在片段B中我再次使用

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

只有这样才能得到想要的结果

当我尝试使用这样的导航 (A->B1) 时,我的底部导航不会将他的选择从 A 更改为 B。

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

导航时,您可以通过以下语句以编程方式更改选择:

bottomNavigation.selectedItemId=R.id.itemFragmentB