Android 没有操作栏的导航抽屉

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20971245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:44:39  来源:igfitidea点击:

Navigation Drawer without Actionbar

androidandroid-navigation

提问by Chinmay Dabke

I searched many sites (stackoverflow as well) but couldn't understand how to implement the navigation drawer without the action bar. I know that this question has already been asked here but it doesn't have a proper explanation and code. I am a beginner in android development so can anyone please explain me with code How to make a navigation drawer without an action bar

我搜索了许多站点(也包括 stackoverflow),但无法理解如何在没有操作栏的情况下实现导航抽屉。我知道这里已经有人问过这个问题,但没有正确的解释和代码。我是 android 开发的初学者,所以任何人都可以用代码我解释如何制作没有操作栏的导航抽屉

Thanks in advance!

提前致谢!

回答by Mehdiway

Just add your DrawerLayoutlike @mohan did, then if you have a button or something you tap on and want to open the drawer, just do like this :

只需添加您DrawerLayout像@mohan 所做的那样,然后如果您有一个按钮或想要打开抽屉的东西,请执行以下操作:

drawer.openDrawer(Gravity.LEFT);

and to close :

并关闭:

drawer.closeDrawer(Gravity.LEFT);

回答by Kim Sant

Starting from the Sample Android NavigationDrawer app:

从示例 Android NavigationDrawer 应用程序开始:

  1. Use the Activity theme: Theme.NoTitleBar
  2. Erase all the ActionBar references in the code
  3. Create a button and in the clickListener call:

    drawer.openDrawer(Gravity.LEFT);

  1. 使用活动主题:Theme.NoTitleBar
  2. 擦除代码中的所有 ActionBar 引用
  3. 创建一个按钮并在 clickListener 调用中:

    drawer.openDrawer(Gravity.LEFT);