相关疑难解决方法(0)

Android 是否可以有多个 nav_graph 文件?

所以我一直在使用Jetpack navigation,碎片的数量一直在增长。

我们可以按照本文档中的描述将不同导航图中的片段分开

喷气背包导航图文档

然后我尝试将不同的导航图放在不同的文件中,因为这样感觉文件更有条理和可读性更强,但是当我尝试导航到不同的 nav_graph 文件时出现以下错误。

nav_graph_start.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_graph_start"
    app:startDestination="@id/splashScreen"
    tools:ignore="UnusedNavigation">

    <fragment
        android:id="@+id/splashScreen"
        android:name="com.timetoface.android.splash.SplashFragment"
        android:label="Login Fragment"
        tools:layout="@layout/fragment_splash">

        <action
            android:id="@+id/action_splash_to_login"
            app:destination="@id/nav_graph_auth"
            />
        <action
            android:id="@+id/action_splash_to_home"
            app:destination="@id/nav_graph_home"
            />
    </fragment>
</navigation>
Run Code Online (Sandbox Code Playgroud)

nav_graph_auth.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_graph_auth"
    app:startDestination="@id/emailLoginScreen"
    tools:ignore="UnusedNavigation">
................................
</navigation>
Run Code Online (Sandbox Code Playgroud)

nav_graph_home.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_graph_home"
    app:startDestination="@id/emailLoginScreen"
    tools:ignore="UnusedNavigation">
................................
</navigation>
Run Code Online (Sandbox Code Playgroud)

从动作 com.app.android:id/action_splash_to_home 引用的导航目的地 com.app.android:id/nav_graph_home 对这个 NavController 来说是未知的

所以,

是否尚不支持多个导航图文件

我是否错过了一些我应该改变的东西?

android kotlin android-jetpack android-jetpack-navigation

2
推荐指数
1
解决办法
3515
查看次数