Android: NavigationDrawer/multiple activities/same menu

Viewed 41032

What I am trying to do, is have a NavigationDrawer menu like this: NavigationDrawer

I've figured out how to change layouts when menu items are clicked, but how do I load a new activity without losing the menu?

My main question:

For example let's say one of my menu options takes you to a layout where there are some buttons that do something. I need to load an accompanying activity/class, that will handle the actions and functionality of that specific "page" in the App. If another menu option takes you to a layout with only an image, for example, that would be another activity without all that code that handles the functionality of the buttons, since there are no buttons in this screen.

I hope that makes sense! I followed many tutorials/videos online using several methods (Fragments etc.) but nothing quite answered my question.

4 Answers

You Have to Take On BaseActivity With Navigation Drawer as Normal Activity. Then after Extend this BaseActvity for all other activity.

Note: In BaseActivity You Have to Take Framelayout Instead of Your Include File like Below. GitHub Code Available Here

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/FullscreenTheme.AppBarOverlay">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="90dp"
        android:background="@color/colorPrimary"
        app:popupTheme="@style/FullscreenTheme.PopupOverlay"
        >

    </androidx.appcompat.widget.Toolbar>

</com.google.android.material.appbar.AppBarLayout>

<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/img_menu_prac_test"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginRight="@dimen/fab_margin"
    android:layout_marginBottom="16dp"
    app:srcCompat="@drawable/ic_practice_test"
    tools:ignore="VectorDrawableCompat"
    app:borderWidth="0dp"
    android:backgroundTint="@color/white"
    app:maxImageSize="58dp"
    />

For Complete Code Visit Github Project Click Here To Download Complete Project Here is Common Navigation Drawer

All activity Design

Related