Home » Android » android – DrawerLayout lock mode doesnt work as expected

android – DrawerLayout lock mode doesnt work as expected

Posted by: admin June 16, 2020 Leave a comment

Questions:

My code below locks the drawerlayout when using a tablet (in landscape mode)

if(condition)
{
    //Landscape mode
    mDrawerLayout.SetDrawerLockMode(DrawerLayout.LockModeLockedOpen);
    mDrawerLayout.SetScrimColor(Color.Transparent);
}
else
{
    //Portrait mode
    mDrawerLayout.SetDrawerLockMode(DrawerLayout.LockModeUnlocked);
    mDrawerLayout.SetScrimColor(Color.LightGray);
}

However, if I open it up in landscape it locks the drawerlayout as expected, however when changing it to portrait mode I cannot swipe it away. It does the opposite when opening it up in portrait (allows me to open and close) but then changing to landscape it opens it but doesn’t lock it in so the user can swipe it away and break the view.

Not to sure what I am missing, as I have stepped through the code countless times and it follows the right paths.

How to&Answers:

I had the same issue and moving that code to my onResume() did the trick.