1

I have implemented a Navigation Drawer successfully using the official documentation and some tutorials. This works perfectly fine.

Now, I have added an In-App-Purchase to unlock the full functionality of my app. This extra functionality is accessed through the Navigation Drawer. I have a boolean which gets a true or false value in the onCreate() of the Activity based on if the user has or not made this purchase.

So far so good.

Now, I wan't to lock the Navigation Drawer if the boolean is false. What is a good/correct way to do this? Do I need to add if-else blocks at all the child fragments where the Drawer is being toggled or affected? Is there any universal lock which I can conveniently use?

Update: I tried using drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) in my Activity.onCreate() after looking at this question, but it does not work.

Community
  • 1
  • 1
rgamber
  • 5,749
  • 10
  • 55
  • 99
  • I did see that question, however the function does not seem to be work. Updating the question now. – rgamber Nov 21 '14 at 05:31
  • you can try making a custom drawer as I described in [this](http://stackoverflow.com/a/26730570/2389078) answer. That way you can manage the button clicks, until the variable is not true, because you'll only be opening the drawer by your wish. I think you get my point. – DroidDev Nov 21 '14 at 05:35

1 Answers1

2

You Can Do Like This.

// enable or disable slide menu
public void setDrawerLayoutEnable(boolean what) {
    if (what) {
        // Drawer will be open through swipe by user
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
    } else {
        // User will not be able to open Drawer but it can be open from application programmatically 
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    }
}

This might helps you.

SilentKiller
  • 6,944
  • 6
  • 40
  • 75
Jay Rathod
  • 11,131
  • 6
  • 34
  • 58