【发布时间】:2021-10-13 06:41:44
【问题描述】:
在家庭片段中,我将 xml 作为
<androidx.constraintlayout.widget.ConstraintLayout
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/bottomNavi"
app:navGraph="@navigation/bottm_navi" />
<meow.bottomnavigation.MeowBottomNavigation
android:id="@+id/bottomNavi"
app:mbn_circleColor="@color/white"
app:mbn_backgroundBottomColor="@color/app_dark_blue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
我的底部导航是
<?xml version="1.0" encoding="utf-8"?>
<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/bottm_navi"
app:startDestination="@id/homeBottomOneFragment">
<fragment
android:id="@+id/homeBottomOneFragment"
android:name="com.krassier.customer.ui.home.bottom.HomeBottomOneFragment"
android:label="fragment_home_bottom_one"
tools:layout="@layout/fragment_home_bottom_one" />
<fragment
android:id="@+id/homeBottomTwoFragment"
android:name="com.krassier.customer.ui.home.bottom.HomeBottomTwoFragment"
android:label="fragment_home_bottom_two"
tools:layout="@layout/fragment_home_bottom_two" />
<fragment
android:id="@+id/homeBottomFourFragment"
android:name="com.krassier.customer.ui.home.bottom.HomeBottomFourFragment"
android:label="fragment_home_bottom_four"
tools:layout="@layout/fragment_home_bottom_four" />
<fragment
android:id="@+id/homeBottomThreeFragment"
android:name="com.krassier.customer.ui.home.bottom.HomeBottomThreeFragment"
android:label="fragment_home_bottom_three"
tools:layout="@layout/fragment_home_bottom_three" />
<fragment
android:id="@+id/homeFragment2"
android:name="com.krassier.customer.ui.home.HomeFragment"
android:label="HomeFragment" >
<action
android:id="@+id/action_homeFragment2_to_homeBottomOneFragment"
app:destination="@id/homeBottomOneFragment" />
<action
android:id="@+id/action_homeFragment2_to_homeBottomTwoFragment"
app:destination="@id/homeBottomTwoFragment" />
<action
android:id="@+id/action_homeFragment2_to_homeBottomThreeFragment"
app:destination="@id/homeBottomThreeFragment" />
<action
android:id="@+id/action_homeFragment2_to_homeBottomFourFragment"
app:destination="@id/homeBottomFourFragment" />
</fragment>
</navigation>
在我写的homefragment中
findNavController().navigate(R.id.action_homeFragment2_to_homeBottomOneFragment)
当我点击底部导航时,我试图在 homefragment 中加载另一个片段,因为底部导航在 home 片段中,但错误是
java.lang.IllegalArgumentException:导航操作/目的地 com.krassier.customer:id/action_homeFragment2_to_homeBottomOneFragment 无法从当前目的地 Destination(com.krassier.customer:id/homeFragment) label=fragment_home class=com.krassier。 customer.ui.home.HomeFragment
【问题讨论】:
-
我只是想将一个片段加载到另一个片段中
标签: kotlin android-jetpack-navigation