0

I want to implement a navigation drawer in my app and I have implement it by referring android developer's guide android developer's guide to navigation drawer. but the problem is that when I opened the app the drawer is not getting closed.it appears on top of other view's and doesn't even responds to swipes.

I have a Tab Activity which has 3 fragments and I've added the drawer layout int the tab activity's layout.

I am not getting whats the problem is? Is it because I've added tab layout and drawer in a same layout.

activity_tab.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<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="package.name.tabs.TabActivity">

    <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/tb_home"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_weight="1"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            app:layout_scrollFlags="scroll|enterAlways"
            app:title="@string/app_name">

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

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

            <android.support.design.widget.TabItem
                android:id="@+id/tab_offers"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/offers_title"/>

            <android.support.design.widget.TabItem
                android:id="@+id/tab_products"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/products_title"/>

            <android.support.design.widget.TabItem
                android:id="@+id/tab_beautypersonal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/beautypersonal_title"/>

        </android.support.design.widget.TabLayout>
    </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_add_card"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:layout_marginBottom="16dp"
        android:layout_marginRight="16dp"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:srcCompat="@android:drawable/ic_dialog_email"/>

    <android.support.design.widget.NavigationView
        android:id="@+id/nv_navigation_drawer"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/navigation_header"
        app:menu="@menu/menu_tab"/>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.DrawerLayout>

Screenshot of the layout

kemblekaran
  • 174
  • 2
  • 14
  • 2
    The drawer `View` - your `NavigationView`, in this case - needs to be a direct child of the `DrawerLayout`. Move it to after the closing `CoordinatorLayout` tag. – Mike M. Apr 05 '18 at 17:21
  • Thanks,It worked.the reason I've added that inside the coordinator layout is that when I added the navigation view inside it it just don't appear in preview window so i think it will also not be shown in the UI.but it worked! thanks @Mike – kemblekaran Apr 05 '18 at 17:29
  • You can use the `tools:openDrawer` attribute to display the drawer as open in the layout designer. Have a look here: https://stackoverflow.com/q/33341472. – Mike M. Apr 05 '18 at 17:32
  • 1
    Thanks @Mike It worked as it should be – kemblekaran Apr 05 '18 at 17:38

1 Answers1

0

The navigation drawer seems to behave normally by implementing solution as suggested by @Mike.I can now swipe through the layout

kemblekaran
  • 174
  • 2
  • 14