Home Ask Login Register

Developers Planet

Your answer is one click away!

dequec64 February 2016

Wait until DrawerLayout animation is done

I have a drawerLayout (support.v4) with a navigationView and have many (like many up to n menu items) menu items. To have less items on the screen at the same time, some menu items lead to another menu with many items.

The thing is, my menu switch works fine, I'm able to pass from one menu to the other one but I have no animation... I want to close the drawer when an item linked to another menu is selected and once the menu is loaded, to open it again.

Here's my code:

navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        public boolean onNavigationItemSelected(MenuItem selectedItem) {
            Log.d(MainActivity.class.getName(), selectedItem.toString());
            MobileXMLMenu menu = UserMenu.getInstance().getMenu();
            for(int i = 0; i < menu.sizeMenuItems(); i++){
                    Log.d(MainActivity.class.getName(), menu.getMenuItem(i).sizeMenuItems() + "");
                    if(menu.getMenuItem(i).sizeMenuItems() > 0){

                        Menu nMenu = navigationView.getMenu();
                        for(int j = 0; j < menu.getMenuItem(i).sizeMenuItems(); j++){
                            MobileXMLMenuItem item = menu.getMenuItem(i).getMenuItem(j);
                        isInSubmenu = true;
            return false;

I also have this for my ActionBarDrawerToggle (don't kn


rehman_mv February 2016

You can use callback methods of the drawer layout from official documentation of the android.

 onDrawerClosed(View drawerView)
 onDrawerOpened(View drawerView)
 onDrawerSlide(View drawerView, float slideOffset)
 onDrawerStateChanged(int newState)

You can find more at link:http://developer.android.com/reference/android/support/v4/widget/DrawerLayout.DrawerListener.html

topcbl February 2016

You can setDrawerListener on DrawLayout like this

        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, mDrawerLayout, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
            public void onDrawerClosed(View view) {

            public void onDrawerOpened(View drawerView) {

handleClickNavigationItem method contains the code which handle navigation event.

And just save clicked item in onNavigationItemSelected method

public boolean onNavigationItemSelected(MenuItem item) {
        mClickedNavigationItem = item.getItemId();
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    return true;

Post Status

Asked in February 2016
Viewed 3,394 times
Voted 11
Answered 2 times


Leave an answer

Quote of the day: live life