我的应用程序中有 2 个模块(应用程序模块和启动模块)。我正在尝试利用<include>标签来使FTUE自包含,而不是文档建议的主导航图的一部分。
我的主导航图在 app 模块中定义,如下所示:
<?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_graph"
app:startDestination="@id/home">
<include app:graph="@navigation/splash_nav_graph"/>
<fragment
android:id="@+id/home"
android:name="com.example.Home"
android:label="fragment_home"
tools:layout="@layout/fragment_home">
<action
android:id="@+id/action_home_to_splash_nav_graph"
app:destination="@id/splash_nav_graph"/>
</fragment>
</navigation>
Run Code Online (Sandbox Code Playgroud)
splash_nav_graph 在 splash 模块中定义(app 模块显然依赖于它):
<?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/splash_nav_graph"
app:startDestination="@id/splashFragment">
<fragment
android:id="@+id/splashFragment"
android:name="com.example.splash.SplashFragment"
android:label="example"
tools:layout="@layout/fragment_splash">
<action
android:id="@+id/action_splashFragment_to_signInFragment"
app:destination="@id/signInFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"/>
</fragment>
<fragment
android:id="@+id/signInFragment"
android:name="com.example.splash.signin.ui.SignInFragment"
android:label="fragment_sign_in"
tools:layout="@layout/fragment_sign_in">
<action
android:id="@+id/action_signInFragment_pop"
app:popUpTo="@id/splash_nav_graph"/>
</fragment>
</navigation>
Run Code Online (Sandbox Code Playgroud)
最后,这是主导航图与应用模块中的 NavHostFragment 绑定的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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" …Run Code Online (Sandbox Code Playgroud) android android-navigation android-architecture-navigation android-navigation-editor