My application contains 6 Activities. I added a Navigation Drawer to my toolbar in all of them in order to toggle between them. I understand that Navigation Drawers are better suited for Fragments and that this adds a lot more code as I'm creating this drawer in each activity but is this ok to do? The application functions fine, I'm just wondering if it's good programming practice? Thank you.
Related
I've created a base activity for navigation drawer and every other activity will extend this to display the drawer.
Doing this will re-create the drawer for each activity.
Is there any kind of workaround for this such that a common drawer is used across all the activities?
EDIT:
Source of what I've referred to do this:
Same Navigation Drawer in different Activities
I prefer using fragments instead of activities when dealing with a navigation drawer, this will both be more efficient and good looking.
A guide on how to do this can be found at:
fragment-navigation-drawer-guide
In short no, or at least: You should not do that.
Navigation drawers are usually to be used with fragments that you swap, they should not create new activities, since the drawer can not (or should not) be shared.
You should overthink your navigation, and use fragments instead where appropriate. Following the design guidelines, again, navigation drawers should be the top most navigation, and no other activities should have one either.
The answer on how to use a common drawer would hence be to use an activity with the drawer managing different fragments.
If you absolutely must, you can detach the navigation drawer view from the layout, keep the reference some place, then reuse the same view in another activity. This is really dirty and as mentioned, you should not do this.
I had an app which was developed 2 years back, now I want to add navigation drawer to that app, but the problem is in that app there are 15 Activities, so do I need to apply the Navigation drawer for all 15 Activities? or is there best way to implement this.?
The navigation drawer items are common for whole app.
Can anyone suggest me the best way to implement this.
A way you can do it, since Navigation Drawers are just list fragments, is create a list fragment and recall that same fragment in all the activities that you want it in. You can do this using the XML Layout Editor to place the fragment in the layout.
Having so many activities, however, makes it a lot of work (especially if your app is designed for multiple sizes and each activity has a layout).
I am going to use Navigation Drawer in my app. I have read about most common approaches of building such apps, a lot of people suggest to change only framgent while selecting different items in navigation drawer. So instead of openning new activity it is better to change fragment of current activity ? Am I right ?
The problem is that I have main activity with two fragments now.
What is the best practice to follow in this case.
To open new activity on item click in navigation drawer ?
To use nested fragments, because my activity already has 2 fragments, so maybe to create some wrapper fragment to nest these two fragments or more if it will be another page.
Please suggest what is the best practice to implement this design pattern in my case.
Technically, the correct way is to change only the fragment while selecting different items in navigation drawer, which would be possible even with only two fragments. There is usually no reason to use nested fragments.
Obviously, there are many ways to do it, and from the UI perspective, there are many possible designs (Navigation Drawer, tabs, sliding pager, etc.)
I was reading about Navigation Drawer and it was not until now that I came into this question: If my top views are going to be accessible through the Navigation Drawer, should I code each of them as Fragments or as Activities?
I want to know the way it was intended to be used, with Fragments or with Activities
The best way is to use Fragments.
When you click on an item, you should always replace the Fragment of your Main Activity without adding the elements in the Back Stack. This will create a seamless dynamic navigation instead of launching new activities and managing the drawer into them.
Here are some references
Google's design guidelines
Google's development guidelines
I have an existing application that has about 25 activities that are navigated to from a "dashboard". I would like to switch and start using the Navigation drawer and fragments. I have gone thru the Nav Drawer design pages online and the example app. My question is what is the best way to convert (structure) my app to fit the Nav Drawer pattern. If I switch my activities to be fragments and use a main activity to replace each fragment as navigation happens, but not sure if that is good b/c for a tablet layout, I might want multiple fragments on my view and not sure if this will limit me. If I go with the other direction I was thinking, keep all my activities and just switch the necessary ones to fragments for tablets but I would need each activity to create the navigation drawer (I think ?) which in my case the drawer is dynamic based on server data. Any suggestions would be great.
Thanks
Brandon
Navigation drawer has to be created for each activity, although you could inherit Activity and create a parent class that handles navigation drawer specific code if code duplication is a concern.
Using a drawer does not limit you to use one fragment per screen, just listen to onClick in drawer and initiate as many fragment transactions as you need.
When it comes to structuring your app, there is no universal advice, I would recommend you to watch Google I/O 2013 talk - Structure in Android App Design. Navigation Drawer is kind of the main theme of the talk.