How to stop the navigation drawer in my Android app from opening automatically?
It used to work fine. Out of sight at first and able to be swiped into visibility. But I
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 View
s 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 View
s 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
.