如果你只是想摆脱ActionBar,就像@GabrieleMariotti建议的那样,你可以使用任何一个*.NoActionBar主题。
或者,如果你已经了解了主题并想要在没有工具栏的情况下使用NavigationUI,有一种方法。
在你的MainActivity的onCreate中:
NavigationView navigationView = findViewById(R.id.nav_view);
navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupWithNavController(navigationView, navController);
您可以像上面那样设置navigationView。就这样。不要像下面那样设置appBarConfiguration:
drawer = findViewById(R.id.drawer_layout);
appBarConfiguration = new AppBarConfiguration.Builder(
R.id.fragment1, R.id.fragment2, R.id.fragment3
).setOpenableLayout(drawer).build();
NavigationUI.setupWithNavController(toolbar, navController, appBarConfiguration);
如果您不想要工具栏,那么这是不必要的。
没有汉堡按钮,您仍然可以通过滑动打开抽屉。如果您想要一个汉堡按钮,请在布局上放置一个按钮,并设置 onClickListener 打开抽屉。
FloatingActionButton fabNavigation = view.findViewById(R.id.fab_navigation)
fabNavigation.setOnClickListener(view1 -> onClick())
抽屉打开方法示例:
public void onClick(View view) {
drawer.openDrawer(GravityCompat.START);
}
.NoActionBar
主题。 - Gabriele Mariotti