NavigationUI使用片段参数导航

问题描述 投票:0回答:1

我有3个相同的片段(片段A)和1个显示错误数据的片段(片段B)。我如何在不创建3个保存动作的情况下往返于fragmentB?

android navigation fragment
1个回答
0
投票

以防万一,我将附上我成功实现的代码:

<fragment
    android:id="@+id/nav_notifications"
    ...
    tools:layout="@layout/fragment_webview">

    <action
        android:id="@+id/to_nav_error"
        app:destination="@id/nav_error" />
</fragment>

<fragment
    android:id="@+id/nav_profile"
    ...
    tools:layout="@layout/fragment_webview">

    <action
        android:id="@+id/to_nav_error"
        app:destination="@id/nav_error" />
</fragment>

<fragment
    android:id="@+id/nav_error"
    android:name="ru.investel.client.screen.main.fragments.ErrorFragment"
    tools:layout="@layout/fragment_error">
</fragment>

用于导航,我使用过:

navController.navigate(R.id.to_nav_error, bundle);
// to return:
navController.popBackStack();
© www.soinside.com 2019 - 2024. All rights reserved.