问题描述
我正在使用 Navigation UI 和 NavigationFragment 用于导航视图,并具有以下依赖性。
implementation 'androidx.navigation:navigation-fragment:2.3.0'
implementation 'androidx.navigation:navigation-ui:2.3.0'
到目前为止,我一直将其用于左侧导航,现在我希望双方都使用 NavigationView 。
我发现了一些问题,但没有为这些新库提供适当的解决方案。
到目前为止,我对双面 NavigationView 所做的操作:
MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinding = DataBindingUtil.setContentView(this,R.layout.activity_main);
setSupportActionBar(mBinding.appBarLayout.toolbar);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_home,R.id.nav_gallery,R.id.nav_slideshow)
.setopenableLayout(mBinding.drawerLayout)
.build();
NavController navController = Navigation.findNavController(this,R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this,navController,mAppBarConfiguration);
NavigationUI.setupWithNavController(mBinding.navView,navController);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top-level destinations.
AppBarConfiguration mAppBarConfiguration = new AppBarConfiguration.Builder(R.id.nav_slideshow)
.setopenableLayout(mBinding.drawerLayout)
.build();
navController = Navigation.findNavController(this,R.id.nav_host_fragment_end);
NavigationUI.setupActionBarWithNavController(this,mAppBarConfiguration);
NavigationUI.setupWithNavController(mBinding.navViewEnd,navController);
}
activity_main.xml
<layout>
<androidx.drawerlayout.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
android:id="@+id/app_bar_layout"
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view_end"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer_end" />
</androidx.drawerlayout.widget.DrawerLayout>
</layout>
当我第一次加载时,它加载的是 HOME-FRAGMENT ,但是当我打开右侧抽屉并单击Fragment时,它一次显示两个, HomeFragment 和 SlideShowFragment
请让我知道如何使用NavigationUI依赖项在导航视图的两侧进行操作。
屏幕截图:
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)