Malay
Malay

Reputation: 71

How to access navigation drawer in all activities without using fragments?

how can i access navigation drawer in all activities without using fragments? I want to access navigation drawer in all activities.I don't want to use fragments.Instead i want to use activities.I know that use of fragments are better than activities. please help me guys.

Upvotes: 2

Views: 1395

Answers (2)

djardon
djardon

Reputation: 161

I think that you can't use 'NavigationDrawer' to do this, you must use 'Fragments' with 'NavigationDrawer' and I recommend you to do it in this way to improve app flexibility and user interface.

First: Google recommend use 'Fragment'. To create a dynamic and multi-pane user interface on Android, you need to encapsulate UI components and activity behaviors into modules that you can swap into and out of your activities. You can create these modules with the Fragment class, which behaves somewhat like a nested activity that can define its own layout and manage its own lifecycle.

Visit http://developer.android.com/training/basics/fragments/index.html

Second: The main content view (the FrameLayout above) must be the first child in the DrawerLayout because the XML order implies z-ordering and the drawer must be on top of the content.

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:background="#111"/>

Visit http://developer.android.com/training/implementing-navigation/nav-drawer.html

Third: You want something like this. 'Navigation Hubs' The navigation drawer is a reflection of your app’s structure and displays its major navigation hubs. Think of navigation hubs as those places in your app that a user will want to visit frequently or use as a jumping-off point to other parts of the app. At a minimum, the navigation hubs are the top-level views, since they correspond to your app’s major functional areas. If your app’s structure is deep, you can add screens from lower levels that your users will likely visit often and make those navigation hubs as well.

Visit http://developer.android.com/design/patterns/navigation-drawer.html

Upvotes: 1

MSaudi
MSaudi

Reputation: 4652

You really should think again about this. Don't be afraid of using fragments, they are good and you will use it a lot in the future. I see that there is no need at all for such design and it's less flexible and will cause bad design and code redundancy. You may mention the full scenario and we can help you designing your app better.

Upvotes: 1

Related Questions