How to stop Android navigation drawer from opening automatically?

会有一股神秘感。 提交于 2019-11-28 14:25:41

It's not that your drawer is opening automatically. It's that the DrawerLayout isn't finding a View to use as the drawer, so both of its direct child Views are filling it. The LinearLayout meant to be the drawer, being listed last, is covering the content View, so it just appears that the drawer is open.

DrawerLayout determines which Views to use as drawers by looking through its direct children for ones with a horizontal layout_gravity setting; i.e., left/right, or start/end. You want this attribute set on the LinearLayout, since it's now acting as the drawer. In your main layout, simply move android:layout_gravity="left" from the ListView to the LinearLayout.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!