1
votes

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!

1

1 Answers

0
votes

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?