In this post i am going to describe how to add navigation drawer to all activities.However, you may want to display navigation drawer in only one of build flavor (ex: pro version). Lets see how can we do this.
Firstly, we need a base activity that holds the navigation drawer. Then all activities that needs a navigation drawer will extend it.
Below is the BaseActivity:
As you see, this Base Activity doesnt call SetContentView in OnCreate. This is left to the Activity that extends BaseActivity. We override SetContentView to add the layout of the Activity that wants to show Navigation Drawer. We inflate the Activity layout with Parent Layout as Navigation Drawer. So in all activities that extends BaseActivity, Navigation Drawer becomes parent layout.
Below is the navigation drawer layout:
In the above layout file, FrameLayout becomes our activity content layout.
Suppose that you dont want to show Navigation Drawer in free version. Then you need to create a BaseActivity that directly inflates the Activity layout as below:
As you see the Navigation Drawer related codes are removed. You need to put this file to free flavor and previos BaseActivity to pro flavor.