其他分享
首页 > 其他分享> > android-在启动时禁用导航抽屉

android-在启动时禁用导航抽屉

作者:互联网

我希望在加载应用程序时禁用导航抽屉,并且如果用户执行某些特定任务,则将其启用.

简而言之,有一种方法可以禁用导航抽屉的切换按钮,并根据用户操作再次启用它.

编辑:
我的活动更新如下:

public class MainActivity extends Activity
    implements NavigationDrawerFragment.NavigationDrawerCallbacks {

    private NavigationDrawerFragment mNavigationDrawerFragment;

    private CharSequence mTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mNavigationDrawerFragment = (NavigationDrawerFragment)
                getFragmentManager().findFragmentById(R.id.navigation_drawer);
        mTitle = getTitle();

        // Set up the drawer.
        DrawerLayout navigationDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mNavigationDrawerFragment.setUp(
                R.id.navigation_drawer,
                navigationDrawerLayout);

        navigationDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    }
}

    @Override
    public boolean onOptionsItemSelected(android.view.MenuItem item) {
        if (item.getItemId() == android.R.id.home) {

        }
        return super.onOptionsItemSelected(item);
    }
    ...
}

但是当应用程序启动时,我可以打开导航抽屉,这是我所不希望的

解决方法:

您只需要使用DrawerLayout setDrawerLockMode()方法锁定和解锁DrawerLayout.

因此,要在关闭模式下锁定DrawerLayout,请使用:

drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

如果您希望将其锁定在打开模式下,请使用canvas.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);

最后,当您想解锁DrawerLayout时,请使用:

drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);

标签:navigation-drawer,android
来源: https://codeday.me/bug/20191029/1957619.html