0

在我的具有 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));
        }
    }

我认为这里所说的逻辑是正确的,但我不知道如何将它用于 NavigationDrawer: 如何在操作栏选项卡中显示选定的片段

4

0 回答 0