我正在构建一个应用,我想在导航抽屉中显示一些其他信息,但是在导航抽屉内部单击后,默认情况下它将关闭,并且我希望它保持打开状态,直到用户在导航抽屉外部单击或按下后退按钮
这可能吗?我该如何实施呢?如果没有,我该如何在不使用导航视图的情况下实现
我尝试使用:mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN); 在我的onCreate和onNavigationItemSelected ...中,在onCreate上使用它默认情况下会打开导航抽屉,使我无法关闭它
这是我的抽屉侦听器代码;
DrawerLayout drawer = findViewById(R.id.drawer_layout);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
答案 0 :(得分:0)
DrawerLayout drawerLayout; // Global variable
drawerLayout = findViewById(R.id.drawer_layout);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
drawerLayout.openDrawer(GravityCompat.START); // Use this line of code where you want to keep open the drawerLayout.
如果您仍然有需要理解的问题,请告诉我。