Disable navigation drawer on startup
I want my navigation drawer to be disabled when loading the app, and if the user has completed some specific tasks, it will be enabled.
In short, there is a way to disable the toggle navigation button and re-enable it based on user action.
Edit: I updated my activity as follows:
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);
}
...
}
but when the app starts, I can open the navigation drawer which I don't want
source to share
You just need to block and unblock yours DrawerLayout
with the method DrawerLayout
setDrawerLockMode()
.
So, to block yours DrawerLayout
in private use:
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
If you prefer to block it in open mode use drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
Finally, if you want to unlock yours DrawerLayout
, use:
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
source to share
write condtion in onoptionsitemselected and block it
@Override
public boolean onOptionsItemSelected(android.view.MenuItem item) {
if (item.getItemId() == android.R.id.home) {
if(yourconditionsatisfied)
{
if (mDrawerLayout.isDrawerOpen(mDrawerLinearLayout)) {
mDrawerLayout.closeDrawer(mDrawerLinearLayout);
} else {
mDrawerLayout.openDrawer(mDrawerLinearLayout);
}
}
}
return super.onOptionsItemSelected(item);
}
source to share