制作应用程序的嵌套图起点

时间:2019-07-09 15:25:53

标签: android android-jetpack android-architecture-navigation android-jetpack-navigation

我有一个嵌套的图(auth),我想将其作为应用程序的起点。您可以在下图中看到将其作为全局图的起始目的地,但是当我启动应用程序时,我会看到{{ 1}}。

enter image description here

任何帮助都将受到欢迎

1 个答案:

答案 0 :(得分:0)

nav_graph.xml中,将此行添加为导航属性。

app:startDestination="@+id/auth"

您不需要输入ID auth。将auth更改为splashFragment

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

在splashFragment中,添加这两行

  app:popUpTo="@id/nav_graph"
  app:popUpToInclusive="true"

应该是这样

 <fragment
        android:id="@+id/splashFragment"
        android:name="co.farouk.SplashFragment"
        android:label="fragment_splash"
        tools:layout="@layout/fragment_splash">
          <action
              app:popUpTo="@id/nav_graph"
              app:popUpToInclusive="true"
              android:id="@+id/action_splashFragment_to_welcomeFragment"
              app:destination="@id/welcomeFragment" />
 </fragment>