Answer the question
In order to leave comments, you need to log in
What should I do to make the Navigation Drawer (side menu) show up on all activities in my app?
I wanted to add a side slide menu Navigation Drawer to my application. I am a beginner developer, so I searched for guides on the Internet and found only this one: habrahabr.ru/post/250765 . Typically, fragments are used for such side menus, so a class is created that inherits from Fragment. But the article used an improved library, with a bunch of good features, and the class inherited from ActionBarActivity. And since everything is different, then I couldn’t think of how to show this menu in other activities now without rewriting all the code with the functionality?
Maybe the author of the article will see the question if I do this: tralchonok
Answer the question
In order to leave comments, you need to log in
Hello. It is more correct, of course, to use fragments.
To show the menu in other Acitvities - in their onCreate initialize the menu in the same way as in the main Activity (as an option, in order not to duplicate the code, inherit all Activities from some base Activity, in which the menu is initialized in onCreate).
Now about why it's bad to do so. When you click on the menu items, as I understand it, you will switch Activity (show different Activities). At the same time, your menu will not be smoothly removed when you click on the element, but the Activity will jump out abruptly. When implemented on fragments, when you click on a menu item, the side menu will smoothly close and the fragment will be displayed in parallel (see how this is done in the Google Play application, poke into the elements of the left menu and understand).
Alteration into fragments is not scary, I can throw you a simple project (in Android Studio) in which this is implemented - do it by analogy. By the way, the implementation with fragments works great with the library that I described in the article on Habré.
UPD: posted an example here: https://github.com/tral/MaterialDrawerFragmentSample
Android 2.0 - Activities
Android 4.0 - Fragments
Currently, using a new Activity for each activity creates an image of a morally obsolete program.
Right now it should be like this: one application - one activity, and inside fragments and dialogs
I suggest you try to describe the functionality of your application using fragments and dialogs.
If you want to make a menu in all your activities, make a base class with the implementation of the menu and inherit all your activities from it.
Do you have different activities with different menus in your project? Doesn't sound like the best idea in terms of usability.
Or do you want to make one menu, but when choosing items, open different activities, not fragments?
In this case, it’s better to deal with the fragments, because then you will probably run into a bunch of troubles.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question