1

I have set up my app with a left and a right side navigation drawer. Everything works great except for one thing.

I would like my other actionbar item to toggle the right navigation drawer. The normal left ActionBarDrawerToggle works great. The Google+ android app notification panel is what I would like the action to mimic.

Here's the code I have for setting up the right side toggle (right now it force closes when clicked):

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            if (mDrawerLayout.isDrawerOpen(mLeftDrawer)) {
                mDrawerLayout.closeDrawer(mLeftDrawer);
            } else {
                mDrawerLayout.openDrawer(mLeftDrawer);
            }

            return true;

        // Right Drawer Toggle

        case R.id.openRd:
            if (mDrawerLayout.isDrawerOpen(mRightDrawer)) {
                mDrawerLayout.closeDrawer(mRightDrawer);
            }
            mDrawerLayout.openDrawer(mRightDrawer);
    }
    return true;
}

If anyone knows how to do this, it would be great if you could let me know!

Thanks!

kevoroid
  • 5,052
  • 5
  • 34
  • 43
Ethan Thomas
  • 264
  • 2
  • 10

1 Answers1

0

When you say "it force closes" do you mean the app crashes, or that the right hand drawer is forced closed? If you are encountering the second situation, it's probably because the there is an else missing before mDrawerLayout.openDrawer(mRightDrawer).

It should be the following:

case R.id.openRd:
if (mDrawerLayout.isDrawerOpen(mRightDrawer)){
    mDrawerLayout.closeDrawer(mRightDrawer);
} else {
    mDrawerLayout.openDrawer(mRightDrawer);
}
return true;

Otherwise I would take a look at this question to ensure that you are setting up the two drawers properly in the XML: Android - Is Navigation Drawer from right hand side possible?

Community
  • 1
  • 1
David Crozier
  • 1,398
  • 2
  • 13
  • 14
  • Yes i see what you are saying however, the app itself crashes as in "App xyz has stopped." A slide from the right side of the screen does open it and it works great. I have set them up actually according to that thread. This issue is really concerning the toggle itself, not the navdrawer. – Ethan Thomas Nov 14 '13 at 23:19