NavigationDrawer with custom fragment inside?

1.9k Views Asked by At

I'm using this library: https://github.com/mikepenz/MaterialDrawer I have a NavigationDrawer on the left with navigation items and on the right I have an additional drawer:

new DrawerBuilder()
        .withActivity(this)
        .withDrawerGravity(Gravity.END)
        .append(result);

I also have a Fragment with a RecyclerView and some additional view inside:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/listBackground">

<android.support.v7.widget.RecyclerView
    android:id="@+id/contactsList"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    tools:listitem="@layout/fragment_contacts_item" />

<LinearLayout
    android:id="@+id/layoutNoContacts"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_centerVertical="true"
    android:orientation="vertical"
    android:paddingBottom="128dp"
    android:visibility="gone">

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:scaleType="fitCenter"
        app:srcCompat="@drawable/sad" />
</LinearLayout>

This fragment inflates the layout and adds entries to the RecyclerView.

This is my main layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary">

    </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:background="@color/listBackground">

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="80dp"
        android:clickable="true" />
</RelativeLayout>

How can I show this custom Fragment which shows my contacts in the NavigationDrawer at all times instead of navigation items?

1

There are 1 best solutions below

3
On

You can is Android Drawer Layout instead of MaterialDrawer. It works like a charm with custom Fragments.

<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 -->
    <fragment android:name="com.example.YourFragment"
        android:id="@+id/left_drawer"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="match_parent" />
</android.support.v4.widget.DrawerLayout>