I have created a toggle drawer where the drawer will slide from the right automatically when the user has clicked on the item displayed in the content view. However, at this point, the drawer can be manually toggled( user can slide open the drawer by swiping from the edge of the screen) open by user as well as toggled open automatically when user clicked on the displayed item. Hence, I have implemented the following code line as mDrawer.setDrawerLockMode(1, GravityCompat.END);
whereby "1" is defined as:
public static final int LOCK_MODE_LOCKED_CLOSED
The drawer is locked closed. The user may not open it, though the app may open it programmatically.
Constant Value: 1 (0x00000001)
However, when debugged, the result is that user can still manually toggle open the drawer and the drawer can still be toggled automatically when item is clicked.
What is actually the desired toggle result is that only the drawer can be toggled out when the item has been selected and not to give user the privilege to manually toggle the drawer.
Hence, could anyone please help to see what wrong or offer some constructive suggestions?
I have attached the following code for your perusal:
mDrawerToggle = new CustomActionBarDrawerToggle(getActivity(), mDrawer);
mDrawer.openDrawer(GravityCompat.END);
mDrawer.setDrawerListener(mDrawerToggle);
//To lock the drawer from being manually toggled
mDrawer.setDrawerLockMode(1, GravityCompat.END);
You can try doing this:
First Call the layout of your drawer:
After that set the lock mode like so:
Then if you want to unlock your drawer again:
or
See if this helps you. :)
EDIT 2:
Now I get it:
Declare your drawer layout and your drawer listview:
On your button/item listener do the following:
For the rationality of the Unlock, I just showed it just incase you want to open the drawer back again.
Don't lock your button, just try my edit first. see if that helps you.
EDIT 3:
Set your Drawer listview and Drawer layout:
Then add this on your listener:
I tested this on my app, I believe this the thing you wanted. So basically the drawer will not open even if the user will try to swipe or click the app icon but it will open once an item is clicked on the content view. which is I believe your desired output.