1

我已经使用左侧和右侧导航抽屉设置了我的应用程序。除了一件事,一切都很好。

我希望我的其他操作栏项目切换右侧的导航抽屉。正常的左侧 ActionBarDrawerToggle 效果很好。Google+ android 应用程序通知面板是我希望模仿的动作。

这是我用于设置右侧切换的代码(现在它在单击时强制关闭):

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;
}

如果有人知道如何做到这一点,如果你能告诉我,那就太好了!

谢谢!

4

1 回答 1

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?

于 2013-11-14T00:15:35.710 回答