我正在我的应用中实现导航视图。
实际上,我可以打开它,点击“汉堡包”图标(在我的工具栏中),然后从左向右跳过。
我想只通过工具栏中的图标打开它,禁用swype。有可能吗?
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, sToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
修改
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); // HERE
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, sToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
如果我使用上面的代码,我使用了DrawerLayout.LOCK_MODE_LOCKED_CLOSED,我同时禁用了icon和swype。
答案 0 :(得分:1)
这适用于我的案例
锁定它:
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
解锁它:
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
希望能帮到你!
答案 1 :(得分:1)
要仅对汉堡包图标上的点击工作而不是滑动,我执行了以下操作,
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, mDrawerLayout, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mDrawerLayout.addDrawerListener(toggle);
toggle.syncState();
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
mDrawerLayout.openDrawer(GravityCompat.START);
}
});