【发布时间】:2022-11-11 11:46:37
【问题描述】:
我的 BottomNavigationView 中有 2 项:
<item
android:id="@+id/first_fragment"
android:enabled="true"
android:icon="@drawable/ic_round_home"
android:title="@fragment_first_title" />
<item
android:id="@+id/second_fragment"
android:enabled="true"
android:icon="@drawable/ic_round_confirmation_number"
android:title="@string/fragment_second_title" />
我已经设置了我的 BottomNavigationView 以使用 NavController:
binding.bottomNavigationBar.setupWithNavController(navController)
我也碰巧有一个thirdFragment,它不包含在BottomNavigationView 中。所以,场景是我首先从firstFragment 导航到thirdFragment。然后从那里,我导航到secondFragment:
findNavController().navigate(thirdFragmentDirections.actionThirdFragmentToSecondFragment())
现在我已经登陆secondFragment,在BottomNavigationView 中选择firstFragment 将不会导航到它!我知道这与导航组件中的多个 backstacks 功能有关,但是我搜索得越多,我就越感到困惑。
【问题讨论】:
-
添加有关代码的更多详细信息(主机导航和设计导航)
标签: android kotlin bottomnavigationview android-navigation