无法使用导航组件从嵌套图片段移动到主图片段

时间:2021-07-25 23:52:47

标签: android kotlin android-fragments navigation fragment

我在主导航图中使用嵌套片段作为底部导航视图,但是当尝试从嵌套图中的片段导航到主导航图中的登录片段时,控制器将我重定向到 homefragment,这是嵌套图的 startDestination

这是我的导航图xml

<?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/nav_main"
    app:startDestination="@id/splashFragment">

    <fragment
        android:id="@+id/splashFragment"
        android:name="package.splash.SplashFragment"
        android:label="fragment_splash"
        tools:layout="@layout/fragment_splash">
        <action
            android:id="@+id/actionGoToHomeFromSplash"
            app:destination="@id/nav_home"
            app:launchSingleTop="true"
            app:popUpTo="@id/splashFragment"
            app:popUpToInclusive="true" />
        <action
            android:id="@+id/actionGoToLogin"
            app:destination="@id/loginFragment"
            app:launchSingleTop="true"
            app:popUpTo="@id/splashFragment"
            app:popUpToInclusive="true" />
    </fragment>
    <fragment
        android:id="@+id/loginFragment"
        android:name="package.signinup.LoginFragment"
        android:label="fragment_login"
        tools:layout="@layout/fragment_login">
        <action
            android:id="@+id/actionGoToHomeFromLogin"
            app:destination="@id/nav_home"
            app:launchSingleTop="true"
            app:popUpTo="@id/loginFragment"
            app:popUpToInclusive="true" />
    </fragment>

    <navigation
        android:id="@+id/nav_home"
        app:startDestination="@id/homeFragment">

        <fragment
            android:id="@+id/homeFragment"
            android:name="package.main.HomeFragment"
            android:label="fragment_home"

            tools:layout="@layout/fragment_home" />
        <fragment
            android:id="@+id/ordersFragment"
            android:name="package.main.OrdersFragment"
            android:label="fragment_orders"
            tools:layout="@layout/fragment_orders" />
        <fragment
            android:id="@+id/settingFragment"
            android:name="package.main.SettingFragment"
            android:label="fragment_setting"
            tools:layout="@layout/fragment_setting">
            <action
                android:id="@+id/actionGoToLoginFromSetting"
                app:destination="@id/loginFragment"
                 />
        </fragment>
        <action
            android:id="@+id/actionGoToLoginFromNavChild"
            app:destination="@id/loginFragment"
         
            />
    </navigation>
</navigation>

0 个答案:

没有答案