[英]Switching between fragments with a button in default Navigation Drawer template of Android Studio
[英]Android Studio - Disabling back button on default Navigation Drawer
所以我创建了默认的导航抽屉活动,并在底部添加了我自己的按钮来手动更改片段。
但是,我不希望将这些按钮添加到后退堆栈,因为我希望导航菜单始终显示汉堡菜单而不是后退按钮。menu 我本质上希望在更改片段时禁用后退按钮和堆栈显示导航抽屉。 我将如何实现这一目标?
这是在 onCreate 的导航活动中
setContentView(R.layout.activity_navigation);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
// 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_projects,
R.id.nav_tools, R.id.nav_share, R.id.nav_send)
.setDrawerLayout(drawer)
.build();
this.navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, this.navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(navigationView, this.navController);
试试这些:
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setDisplayShowHomeEnabled(false);
使用 NavController.OnNavigatedListener 更新工具栏图标。
val navController = Navigation.findNavController(this, R.id.fragment_main_navHost)
navController.addOnNavigatedListener(contoller, destination -> {
if(destination.id == R.id.fragmentTwo){
// update the toolbar here
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.