带有导航架构组件导航但重叠底部导航视图的片段内的 BottomNavigationView

时间:2021-05-04 06:52:19

标签: android-architecture-components bottomnavigationview navigationcontroller android-bottomnavigationview

我的底部导航视图位于片段中。下面是代码


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragments.investors.InvestmentParentFragment">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:itemIconTint="@drawable/nav_selector"
        app:itemTextColor="@drawable/nav_selector"
        app:menu="@menu/investments_bottom_nav_menu"
        android:layout_gravity="bottom"
        android:layout_alignParentBottom="true"
        app:itemRippleColor="@color/secondaryLightColor"
        android:background="@drawable/bottom_nav_background"
        />

</RelativeLayout>

当我点击底部导航视图中的一个项目时,它会导航到一个片段。我遇到的问题是,当我导航到一个新片段时,它会打开新片段并且底部导航视图消失我希望它像底部导航视图在 MainActivity 中的方式一样工作,当我导航到一个新片段时不会消失它留在那里并且可以像标签布局一样操作

这是我在具有底部导航视图但不起作用的片段中尝试过的。内部 onViewCreated 方法


 Navcontroller navController = Navigation.findNavController(view); 

 bnvInvestments = view.findViewById(R.id.bnv_investments);

 NavigationUI.setupWithNavController(bnvInvestments, navController);



0 个答案:

没有答案