5

I'm fairly new to android programming and developed an app that has a Navigation Drawer implemented. Per Google guidelines, i'd like the NavDraw to start open but am unable to do this.

This is my onCreate (I guess this is where I should implement this feature, right?)

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActionBar().getThemedContext(), android.R.layout.simple_list_item_1, menuEntries);

    final DrawerLayout drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
    final ListView navList = (ListView) findViewById(R.id.drawer);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    drawerToggle = new ActionBarDrawerToggle(
            this,
            drawer,
            R.drawable.ic_drawer,
            R.string.drawer_open,
            R.string.drawer_close
    ) 

(...)

surubutna
  • 87
  • 2
  • 7

2 Answers2

7

Use drawer.openDrawer(Gravity.LEFT);

Aboalnaga
  • 602
  • 6
  • 16
  • 4
    If targeting international users, use GravityCompat.START instead. – wize Oct 23 '15 at 18:19
  • You should probably wrap in `if (savedInstanceState == null)`, so that the drawer doesn't open on configuration/orientation change – Jacob R Aug 30 '17 at 20:40
1

You can use

 drawer.openDrawer(Gravity.LEFT);

or

drawer.openDrawer(Gravity.RIGHT`);
Hoque MD Zahidul
  • 10,560
  • 2
  • 37
  • 40