问题描述
我正在构建一个应用程序,我想在导航抽屉中显示一些附加信息,但在导航抽屉内部单击后,默认情况下它会关闭,我希望它保持打开状态,直到用户单击导航抽屉外部或按下后退按钮
I'm building an app where I want to show some additional information in the navigation drawer but after clicking inside of the navigation drawer it closes by default and I would like it to remain open till the user click outside the navigation drawer or presses the back button
这可能吗?我该如何实施?如果不是,我如何在不使用导航视图的情况下实现它
Is this possible? And how do I implement it ? If not how else can I implement it without using the navigation view
我尝试过使用: mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);在我的 onCreate 和 onNavigationItemSelected ...在 onCreate 上使用它默认打开导航抽屉让我无法关闭它
I have tried using: mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);In my onCreate and onNavigationItemSelected ...Using it on the onCreate opens up the navigation drawer by default leaving me unable to close it
这是我的抽屉监听器代码;
This is my drawer listener code;
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();
推荐答案
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.
如果您仍然无法理解,请告诉我.
If you still have problem to understand please let me know.
这篇关于保持导航抽屉打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!