Navigation drawer with multiple activities example code download android






















Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. START ;. The drawer icon is displayed on all top-level destinations that use a DrawerLayout. Have a look at the following image to get an idea about the Navigation drawer.

Skip to content. Change Language. Related Articles. Table of Contents. This Frame Layout is used to bind the layout of children layouts. Open your BaseActivity. Drawer Layout is used to implement the Sidemenu in Android. Here, class and SecondActivity.

Step 3 Replace setContentView in the onCreate method of the class files created in step2 as shown below. Coding Part setContentView R. In this way, you can use the same NavigationView for all the activities. We can create other activities with the same approach to show NavigationView. Download Code You can download the full source code for this article from GitHub.

I personally prefer this method but it has its limitations. Create a baseactivity in which the code for the navigation drawer is. The activities that need to have the drawer extend this baseactivity instead of appcompatactivity or activity. The layout inflation works like this in the oncreate: getLayoutInflater. Here the activities are started through startActivity. Trying to do this in the first method would involve main activity implementing huge number of interfaces unnecessarily you will learn about interfaces in inter-fragment communication.

If you start a new activity, you will lose your menu because the new activity will cover the old activity. You need to use fragments for this. Think of fragments as activities that can live within another activity. Then after Extend this BaseActvity for all other activity. GitHub Code Available Here. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 5 years, 8 months ago. Active 2 years, 1 month ago.

Viewed 40k times. What I am trying to do, is have a NavigationDrawer menu like this: NavigationDrawer I've figured out how to change layouts when menu items are clicked, but how do I load a new activity without losing the menu? My main question: For example let's say one of my menu options takes you to a layout where there are some buttons that do something.

Improve this question.



0コメント

  • 1000 / 1000