具有底部导航视图的导航组件导航到另一个图形片段

时间:2020-06-22 22:05:29

标签: android android-fragments bottomnavigationview android-jetpack android-jetpack-navigation

实际上,我正在使用google NavigationAdvanceSample(https://github.com/android/architecture-components-samples/tree/master/NavigationAdvancedSample)来解决底部导航保存状态问题。

我在底部的导航栏上有2个按钮,以及2个导航图,其描述如下:

NAV MAP(A):MapFragment(A1)

导航用户(B):回收站(B1)->用户分段(B2)

我已使用以下代码解决了用户片段到GoogleMap(B2-> A1)之间的导航: NavHostFragment.findNavController(UserFragment.this).navigate(R.id.action_UserFragment_to_mapGraph,bundle);

user.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/user"
    app:startDestination="@+id/user">

    <fragment
        android:id="@+id/user"
        android:name="com.example.userFragment"
        tools:layout="@layout/fragment_user" >
        <action
            android:id="@+id/action_userFragment_to_mapGraph"
            app:destination="@id/map"
            app:popUpTo="@id/map"
            app:popUpToInclusive="true"/>
    </fragment>
    <include app:graph="@navigation/map" />
</navigation>

我仍然无法解决的问题是,当我单击底部导航栏中的MAP按钮时,我在其自己的地图片段中有一个新的地图实例。如果再次单击navuser按钮(B),则会看到从用户片段(B2)调用的地图。

当我从用户片段(B2)调用地图片段时,我想更正此问题,使其显示在A1片段中,同时NAVMAP按钮也显示为选中状态(A)。另外,如果我选择用户按钮(B),则显示用户片段的最后一个屏幕。

谢谢!

0 个答案:

没有答案