【问题标题】:BottomNavigationView stops working after navigating from another fragment从另一个片段导航后,BottomNavigationView 停止工作
【发布时间】: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


【解决方案1】:

为了避免这种行为,我们可以通过以下方式设置BottomNavigationView

NavigationUI.setupWithNavController(binding.bottomNavigationBar, navController, false)

【讨论】:

    猜你喜欢
    • 2020-09-03
    • 1970-01-01
    • 1970-01-01
    • 2013-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-02
    • 1970-01-01
    相关资源
    最近更新 更多