Show Navigation drawer in every activity - android studio - android

I have a problem...I am developing an app in android studio.In the meantime,there is already a navigation drawer in it.But the problem is, it only appears in the home screen.When it goes to another screen, the navigation drawer is not shown. I am new to android studio but i know some of Java languages.Can anyone help me with providing anything that would help me make the navigation drawer show in all of slides and pages in my app.

from docs
Navigation Drawer
The navigation drawer is a panel that displays the app’s main
navigation options on the left edge of the screen. It is hidden most
of the time, but is revealed when the user swipes a finger from the
left edge of the screen or, while at the top level of the app, the
user touches the app icon in the action bar.
for achieve what you asked you have to use Fragments
Fragment represents a behavior or a portion of user interface in an
Activity. You can combine multiple fragments in a single activity to
build a multi-pane UI and reuse a fragment in multiple activities. You
can think of a fragment as a modular section of an activity, which has
its own lifecycle, receives its own input events, and which you can
add or remove while the activity is running (sort of like a "sub
activity" that you can reuse in different activities).
see this examples for more details
1. Navigation Drawer - android hive
2. Navigation Drawer exp 2
3. Navigation Drawer exp 3
Refer this answer also
Answer

You have to add fragments in that activity where the navigation drawer exist. Whenver the user will click on the option in the navigation drawer the view should be changed by replacing with the required fragment.So by using the fragments user will stay on the same activity but just the views will be changed in that activity. you can refer to the fragments documentation provided by android developers. https://developer.android.com/guide/components/fragments.html

Related

Android Navigation with nested bottom navigation

I'm new to Android Navigation Component and want to understand how can I use it in my relatively simple scenario where I want to have a single activity approach. I obviously want the system to handle the back stack, also for bottom navigation.
What I need is 2 very simple cases:
1. Mixed destinations
Some of the destinations in my navigation graph have bottom navigation, and some not. Imagine that I have a login flow without a bottom navigation and then move to the "real app" where I have bottom navigation. Google says put bottom navigation, drawer, action bar outside of navigation graph, which means they are shown for all destinations.
Is this supported by Navigation Component? Without dirty hacks of hiding/showing bottom nav.
2. Full screen popups
Another question - is multiple navhosts supported? Imagine I have a UI with bottom navigation and action bar, which are outside of the nav host area. But then I need to show a full screen popup, like a dialog or a resource selection screen, which will also go over the bottom nav and action bar.
Can I do this as a destination in navigation graph?
For both questions any conceptually supported solution is good for me, including switching graphs/hosts during navigation.
As per the Listen for navigation events documentation:
As an example, you might have common UI elements that you intend to show in some areas of your app while hiding them in others. Using your own OnDestinationChangedListener, you can selectively show or hide these UI elements based on the target destination
So yes, you can selectively show or hide elements of your activity's UI when you move to certain destinations, such as your login screen.
As per the Create a destination from a DialogFragment documentation:
If you have an existing DialogFragment, you can use the <dialog> element to add the dialog to your navigation graph
This also supports other types of DialogFragment such as a BottomSheetDialogFragment.

android - How to implement navigation with bottom app bar

I have a project with the following 4 layouts:
I have actually 1 activity holding a bottom app bar and the NavHostFragment where the fragments get injected. The Main Fragment is the home view. There is a Management and a Setting fragment, both are top-level views like the home view but doesn't depend on each other. These 3 fragments can be switched by clicking an item in the nav drawer. For simplification, I'm trying the new navigation architecture component.
Now I have some design questions:
Should I move the bottom app bar into the fragments, cause they don't depend on each other and the FAB button has another action, otherwise I had to change the onClickListener in the activity when the fragments switch?
1.1 Or should I even show the bottom app bar in the management fragment? Maybe just the top bar with the Up caret.
1.2 Or bottom app bar + top bar and Up caret
1.3 and what about the drawer icon, should I display it in the Mgmt fragment
Should I use a fragment or an activity for the Settings fragment? When I use a fragment, I have to move the bottom app bar into the fragments. Otherwise, the bottom app bar would be visible in the Settings Fragment
The Management Fragment has just a recycler view. Clicking on an item should open a DetailView. Should I use a fragment or an activity here?
I read the doc about the navigation architecture component and there is a section about customizing the destination. Also, ich checked the source code and know that the fragments get replaced.
Further, I checked out some frequently used Apps how they implemented the navigation with a nav drawer and noticed, they all replace their fragments. Why does no one hide/show the fragments, is there a reason not to doing this?
Assume we have a fragment with a listview that holds data collected from a database or another expensive task. So wouldn't it be better to show/ hide these fragments instead of replacing it?
Sorry, it's my first app and I'm really confused about this topic, and it seems there are no official recommendations about it out there not even Material Design guidelines don't really make a reference about it.
How would you do it?
setupWithNavController on a Toolbar (or subclasses like BottomAppBar) only set up the Up icon and the title - they do not hook up menu items added to the Toolbar.
As per the Tie destinations to menu items documentation, you must set up your own listener and call onNavDestinationSelected(). For a BottomAppBar, that would be done by setting a Toolbar.OnMenuItemClickListener:
val navController = Navigation.findNavController(this, R.id.navigation_fragment)
myBottomBar.replaceMenu(R.menu.menu_with_nav_item)
myBottomBar.setupWithNavController(navController)
// Connect MenuItems to the NavController
myBottomBar.setOnMenuItemClickListener { menuItem ->
menuItem.onNavDestinationSelected(navController)
}

Android navigation drawer with fragments

I have an activity that extends fragmentActivity that has a navigation Drawer, and three different fragments.
Is there a way to make a navigation Drawer that has different buttons inside each of my fragments?
For example when you enter fragment 1 you will see certain buttons in the navigation Drawer, and when you go to fragment 2 you will see different buttons in the navigation Drawer.
You should just define which options are to be displayed in the NavigationDrawer depending on which current Fragment you're on, using a switch statement or if statement.
Check out this link:
How to change fragments using Android navigation drawer
Also, from this link https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html
As per the Android Design guide, any drawers positioned to the
left/start should always contain content for navigating around the
application, whereas any drawers positioned to the right/end should
always contain actions to take on the current content. This preserves
the same navigation left, actions right structure present in the
Action Bar and elsewhere.
So this type of thing seems like it was planned for when the NavigationDrawer was designed.

Master/detail flow or navigation drawer ? which is better for display detail data about list items?

I have a list of persons that when user click on one item the app show its detail ! i used dual pane Master/detail design pattern for tablet size and for small size it just replace list with detail fragment.
The problem is that my manager think its better to change this design with navigation drawer ! what is the best choice for this case ? navigation drawer or master/detail design ?
which is better for user experience ?
The Navigation Drawer is:
a panel that transitions in from the left edge of the screen and displays the app’s main navigation options.
Per the App Structure guide:
A navigation drawer is a slide-out menu that allows users to switch between views of your app. It can hold a large number of items and is accessible from anywhere in your app. Navigation drawers show your app's top-level views, but can also provide navigation to lower-level screens. This makes them particularly suitable for complex apps.
And the Material Design structure guidelines state:
The content in the left nav is ideally navigation- or identity-based.
The Navigation Drawer is not listed as a mechanism for multi-pane layouts, while a master/detail multi-pane layout is specifically mentioned.
In short: Navigation Drawer is for navigation only and not for displaying a master list with corresponding detail.
In fact, one of the framework engineers wrote a Google+ post back in 2013 specifically about how they tried to use DrawerLayout (the class name for the navigation drawer) for displaying master/detail style content and instead built a separate component, SlidingPaneLayout specifically to address this issue of displaying master/detail on smaller screens without using the Navigation Drawer affordances or pattern as they just did not fit. Note that this has fallen slightly out of favor in Material design, with a re-emphasis on a traditional master/detail pattern with meaningful transition animations.
You can create 2 demo apps to see the difference on a phone.
Master Detail flow:
The master page (menu, or list page) will always be displayed to the user first and the master page covers the whole screen. If the user does not tap, he/she will not notice there is a detailed page.
Navigation drawer:
The detailed page will be displayed to the user first, with a navigation menu (3 stripes menu) on the top left corner.
If the user taps the navigation menu, he/she will see a sliding out page, which covers only half of the screen. For the most of the time, the menu screen will be hidden.
So they are actually very different from the design aspect. Of course, they have similarities during implementation.

Android Navigation Drawer Design

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.

Categories

Resources