导航抽屉旋转错误

时间:2015-07-04 15:27:39

标签: android navigation-drawer onrestoreinstancestate

在我的活动中旋转后有一个NavigationDrawer,onRestoreInstanceState

出错
Caused by: java.lang.IllegalStateException: setSelectedNavigationIndex not valid for current navigation mode
            at android.support.v7.internal.app.WindowDecorActionBar.setSelectedNavigationItem(WindowDecorActionBar.java:420)
            at ir.parsdroid.telegrameducation.Tools.enhanced.onRestoreInstanceState(enhanced.java:118)

我的代码:

@Override
    public void onSaveInstanceState(Bundle outState) {
        // Serialize the current dropdown position.
        outState.putInt(STATE_SELECTED_NAVIGATION_ITEM,
                getSupportActionBar().getSelectedNavigationIndex());
    }

    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {
        // Restore the previously serialized current dropdown position.
        if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) {
            getSupportActionBar().setSelectedNavigationItem(
                    savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM));
        }
    }

我认为这里说的Logic是真的,但我不知道如何将它用于NavigationDrawer: How to show selected fragment in action bar tab

0 个答案:

没有答案