Android NavigationView使用Android NavigationUI+;导航控制器
我使用导航UI和导航片段作为导航视图,使用以下依赖项Android NavigationView使用Android NavigationUI+;导航控制器,android,navigation-drawer,navigationview,android-navigationview,Android,Navigation Drawer,Navigationview,Android Navigationview,我使用导航UI和导航片段作为导航视图,使用以下依赖项 implementation 'androidx.navigation:navigation-fragment:2.3.0' implementation 'androidx.navigation:navigation-ui:2.3.0' 到目前为止,我一直使用它进行左侧导航,现在我需要两侧导航视图 我发现了一些问题,但没有为这些新库找到合适的解决方案 到目前为止,我为双方所做的导航视图: MainActivity.java @Overri
implementation 'androidx.navigation:navigation-fragment:2.3.0'
implementation 'androidx.navigation:navigation-ui:2.3.0'
到目前为止,我一直使用它进行左侧导航,现在我需要两侧导航视图
我发现了一些问题,但没有为这些新库找到合适的解决方案
到目前为止,我为双方所做的导航视图:
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, navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(mBinding.navViewEnd, navController);
}
活动\u 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>