Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Navigation Drawer at startup

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
    ) 

(...)

like image 375
surubutna Avatar asked Apr 26 '14 22:04

surubutna


People also ask

Where is the navigation drawer?

The user can view the navigation drawer when the user swipes a finger from the left edge of the activity. They can also find it from the home activity by tapping the app icon in the action bar. The drawer icon is displayed on all top-level destinations that use a DrawerLayout.

What is NavigationView in Android?

com.google.android.material.navigation.NavigationView. Represents a standard navigation menu for application. The menu contents can be populated by a menu resource file. NavigationView is typically placed inside a DrawerLayout .


2 Answers

Use drawer.openDrawer(Gravity.LEFT);

like image 98
Aboalnaga Avatar answered Sep 24 '22 01:09

Aboalnaga


You can use

 drawer.openDrawer(Gravity.LEFT);

or

drawer.openDrawer(Gravity.RIGHT`);
like image 23
Hoque MD Zahidul Avatar answered Sep 24 '22 01:09

Hoque MD Zahidul