Вопрос

I'm used to using a 3rd party library for implementing a navigation drawer (sliding menu) in Android, but I want to use the native version from now. I went through the tutorial (http://developer.android.com/training/implementing-navigation/nav-drawer.html) which is pretty straight forward.

I typically extend the 3rd party navigation drawer to each activity by defining the configuration in a base class. The new nav drawer, however, swaps fragments in and out, which my research indicates is the standard way of managing your displays.

This seems fine, but my app has a fairly complex hierarchy of pages and navigation. Like most apps, it contains more fragments than just the ones in the menu.

So if I have 3 nav drawer items for fragments A, B, and C, and I can only load fragment D from fragment C, do I handle that navigation logic in the activity where I configure the nav drawer? It seems like kind of a nightmare to have one container to swap out an indefinite number of fragments, especially if the work flow is deep.

From what I can gather on Stack, there seem to be a lot of people who are familiar with extending a 3rd party drawer in each Activity, but when they switch over to the native version there is confusion.

So to summarize, I understand the fragment swapping aspect of the navigation. I just don't understand how the rest of the work flow navigation would work, say if I had several detail screens below a nav item fragment. If anyone can give me some hints on how best to approach this scenario, maybe I can experiment and post some code for future readers.

Это было полезно?

Решение

For navigation in Android there is always one thing you have to remember:

  • If you stay on the same level of the navigation hierarchy, for example when swiping through pages, you use Fragments.
  • When you move up and down in the navigation hierarchy, for example going to a detail view, you would start a new Activity and displayed the Fragment with the detail content in it.

A NavigationDrawer is used for top level navigation in your app to quickly navigate between different parts of your app. It's kind of like a main menu. With that in mind you need to determine if a NavigationDrawer makes sense in your app. It's all about how the user should navigate through the content. If there is just one path for the user to follow for example if you start out with just one screen and from then on the user can just go deeper and deeper in the navigation hierarchy from one detail view to the next than a NavigationDrawer does not make much sense. But if there are multiple paths the user can take that lead into different, independent parts of your app without one dedicated start screen on which everything else depends than a NavigationDrawer sounds pretty reasonable.

You can look at Google apps like Gmail, Drive or Google+ to see how a NavigationDrawer is supposed to be used.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top