我正在使用一个使用许多片段的Activity,但是我不知道如何设置2个navHostFragments: 带有底部导航栏的主机片段只能在nav_login目的地中显示
我正在使用数据绑定和导航组件:
这是我的代码和结构:
发生我的头痛时:(辅助导航图和navHostFragment(位于hostFragment上),nav_login.xml:
<navigation 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:id="@+id/nav_login"
app:startDestination="@id/mainFragment">
<fragment
android:id="@+id/expensesFragment"
android:name="com.abner.syncittechnologies.expenses.ExpensesFragment"
android:label="expenses_fragment"
tools:layout="@layout/expenses_fragment" />
<fragment
android:id="@+id/mainFragment"
android:name="com.abner.syncittechnologies.main.MainFragment"
android:label="main_fragment"
tools:layout="@layout/main_fragment" />
<fragment
android:id="@+id/incomesFragment"
android:name="com.abner.syncittechnologies.incomes.IncomesFragment"
android:label="incomes_fragment"
tools:layout="@layout/incomes_fragment" />
</navigation>
我的hostFragment(我的辅助navHostFragment和底部导航栏在哪里):
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment2"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/nav_login" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
style="@style/Widget.Design.BottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/nav_drawer" />
</androidx.constraintlayout.widget.ConstraintLayout>
我的菜单项是:
<item
android:id="@+id/mainFragment"
android:enabled="true"
android:icon="@drawable/ic_home_nav"
android:title="Inicio"
app:itemIconTint="?attr/colorOnSurface"/>
<item
android:id="@+id/incomesFragment"
android:enabled="true"
android:icon="@drawable/ic_app_concept"
android:title="Control"/>
<item
android:id="@+id/expensesFragment"
android:enabled="true"
android:icon="@drawable/ic_app_concept"
android:title="Inventario"/>
并且我正在HostFragment上使用以下代码:
binding.bottomNavigation.setupWithNavController(this.findNavController())
编译并显示导航底部栏和主要片段,但导航栏不起作用
和我的导航图捕获