如何阻止appbarconfiguration将汉堡包图标切换到后退箭头?

z9smfwbn  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(349)

如何将汉堡包图标取回导航抽屉?这个 AppBarConfiguration 把它改成背箭,为什么?
下面是我的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    context = this;

    init_v3();
    BottomNavigationView navView = findViewById(R.id.nav_view);
    // Passing each menu ID as a set of Ids because each
    // menu should be considered as top level destinations.
    AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(R.id.home, R.id.nav_tasks)
            .build();
    NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
    NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
    NavigationUI.setupWithNavController(navView, navController);

}
lsmd5eda

lsmd5eda1#

您应该添加所有不希望“向上/向后”按钮显示在 appBarConfiguration 在您的示例中,此up/back按钮不会显示在中 R.id.nav_tasks & R.id.home 已添加的片段。>>如果你有更多的片段,那么把它们添加到下面的列表中,用逗号分隔。
要显示抽屉汉堡图标,你需要打电话 setOpenableLayout(drawerLayout) ```
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);

AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.home,
R.id.nav_tasks)
.setOpenableLayout(drawerLayout)
.build();

相关问题