BottomNavigationView with Splash Screen(体系结构导航组件)



我已经用bottomNavigationView实现了导航,如中所示图表
如果选择main_graph作为"起始目的地",则导航工作正常。但是,如果我选择fragment_splash作为"起始目的地",并使用popUpToInclusive从中导航到main_graph,则BottomNavigation无法按预期工作。(它完全搞砸了,在底部图标之间导航时碎片不会被破坏等(

我的嵌套main_graph有自己的"起始目的地",它应该是BottomNavigationView的起始目的地。

我采用"单一活动"的方法。

如何解决这个问题?非常感谢。

只需像这个一样为BottomNavigationView实现onNavigationItemSelected

@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
NavOptions navOptions = new NavOptions.Builder()
.setPopUpTo(R.id.nav_home, false)
.build();
navController.navigate(id,null, navOptions);
}

在我的情况下,我已经在BottomNavigation 中定义了与菜单项ID相同的目的地名称

这是我的图形xml

<?xml version="1.0" encoding="utf-8"?>
<navigation
android:id="@+id/main_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"
app:startDestination="@id/splashFragment">
<fragment
android:id="@+id/splashFragment"
android:name="com.businesslinktrading.makanilebanon.SplashFragment"
android:label="fragment_splash"
tools:layout="@layout/fragment_splash">
<action
android:id="@+id/action_splashFragment_to_nav_home"
app:destination="@id/navigation4"
app:launchSingleTop="true"
app:popUpTo="@+id/main_navigation"
app:popUpToInclusive="true"/>
</fragment>
<navigation android:id="@+id/navigation4"
app:startDestination="@id/nav_home">
<fragment
android:id="@+id/nav_emergancy_phones"
android:name="com.businesslinktrading.makanilebanon.EmergenciesFragment"
android:label="fragment_emergencies"
tools:layout="@layout/fragment_emergencies"/>
<fragment
android:id="@+id/nav_moods"
android:name="com.businesslinktrading.makanilebanon.MoodsFragment"
android:label="fragment_moods"
tools:layout="@layout/fragment_moods"/>
<fragment
android:id="@+id/nav_home"
android:name="com.businesslinktrading.makanilebanon.ForYouFragment"
android:label="fragment_for_you"
tools:layout="@layout/fragment_for_you"/>
<fragment
android:id="@+id/nav_groups"
android:name="com.businesslinktrading.makanilebanon.GroupsFragment"
android:label="fragment_groups"
tools:layout="@layout/fragment_groups"/>
<fragment
android:id="@+id/nav_parking"
android:name="com.businesslinktrading.makanilebanon.ParkingFragment"
android:label="fragment_parking"
tools:layout="@layout/fragment_parking"/>
</navigation>
</navigation> 

最新更新