-1

I am a beginner here in android and I am trying out different things. I wanted to create a navigation drawer with view pager. But whenever I do that the navigation drawer just doesn't seem to cover up the toolbar on top. I've tried out many different things. Here's the link to the tutorial I used.

https://androidbelieve.com/navigation-drawer-with-swipe-tabs-using-design-support-library/

Here's a screenshot of my app

This is activity_main

<LinearLayout 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:fitsSystemWindows="true"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:title="Tuition Manager" />

    <android.support.v4.widget.DrawerLayout
        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/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:openDrawer="start">

        <FrameLayout
            android:id="@+id/containerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"></FrameLayout>

        <android.support.design.widget.NavigationView xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:layout_marginTop="-24dp"
            app:headerLayout="@layout/nav_header_main"
            app:menu="@menu/activity_main_drawer" />
    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

This is content_main

<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:fitsSystemWindows="true"
    tools:context="com.gupta.aayush.tuitionmanager.ContentMainActivity">

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

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@drawable/ic_action_add_user" />

</android.support.design.widget.CoordinatorLayout>

Help please!

Aayush Gupta
  • 55
  • 11
  • From the flagging options (emphasis mine) - "_Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and **the shortest code necessary to reproduce it in the question itself**. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example._" – takendarkk Mar 13 '17 at 15:53
  • An image in this case would also be very useful – Ruben Aalders Mar 13 '17 at 15:57
  • @takendarkk I want the navigation drawer to cover up the whole screen's height. – Aayush Gupta Mar 13 '17 at 16:55
  • And I want you to post the most minimal amount of code required to reproduce the problem in your question. – takendarkk Mar 13 '17 at 17:01
  • @takendarkk Did that too! Can you help? – Aayush Gupta Mar 13 '17 at 17:34
  • Your `Toolbar` needs to go inside the `DrawerLayout`'s content `ViewGroup`. The duplicate linked at the top of your question shows what to do. – Mike M. Mar 13 '17 at 17:38
  • Had to add the toolbar and the container in LinearLayout. But that did the trick. Thanks @MikeM. – Aayush Gupta Mar 13 '17 at 17:57
  • Yep, that's exactly how to do it. You probably don't need that outer `LinearLayout` anymore, btw, if you still have it. Glad you got it working. Cheers! – Mike M. Mar 13 '17 at 17:59

1 Answers1

-1

Change the xml layout of activity_main.xml to be

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:id="@+id/drawerLayout"
    >
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:orientation="vertical">

        <FrameLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/containerView">
        </FrameLayout>

        <android.support.design.widget.NavigationView
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:id="@+id/shitstuff"
            app:itemTextColor="@color/black"
            app:menu="@menu/drawermenu"
            android:layout_marginTop="-24dp"
            />

        </LinearLayout>

    </android.support.v4.widget.DrawerLayout>

Here I made the drawer layout the parent of the screen, And removed the toolbar to be in the next layout

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    app:tabGravity="fill"
    app:tabMode="fixed"
    android:background="@color/material_blue_grey_800"
    app:tabIndicatorColor="@color/orange"
    app:tabSelectedTextColor="@color/orange"
    app:tabTextColor="@color/white"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</android.support.design.widget.TabLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</android.support.v4.view.ViewPager>

Omar HossamEldin
  • 3,033
  • 1
  • 25
  • 51
  • Thanks for the reply but this didn't help. It further messed up the app. Now the navigation drawer is at the bottom of the screen and is always showing. P.S I would add a screenshot but I don't know how – Aayush Gupta Mar 13 '17 at 16:44