Fullscreen navigation drawer
Asked Answered
D

6

10

I have a navigation drawer like this.

What I want to do is open my drawer to fullscreen not half screen. How do I make this drawer to open as full screen?

This is xml of drawerlayout

<?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:fitsSystemWindows="true">

<include
    android:id="@+id/toolbar_layout"
    layout="@layout/app_toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/toolbar_layout"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <FrameLayout
        android:id="@+id/activityMainContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/colorPrimary"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:itemTextColor="@android:color/white"
        app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
Decay answered 18/5, 2017 at 10:19 Comment(0)
N
36

You can try this navigationView property 100% work

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    android:layout_marginEnd="-65dp"
    android:layout_marginRight="-65dp"
    app:itemTextColor="@color/lightgray"
    app:itemIconTint="@color/colorAccent"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer" />
Nobles answered 18/5, 2017 at 10:28 Comment(0)
F
2

try this hope it works:

<include
        android:id="@+id/left_drawer"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        layout="@layout/drawer"
        android:layout_marginLeft="-64dp"/>
Frugal answered 18/5, 2017 at 10:25 Comment(0)
M
0

You have to put your DrawerLayout as a main layout in your xml like this:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/toolbar_layout"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

<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:fitsSystemWindows="true">

<include
    android:id="@+id/toolbar_layout"
    layout="@layout/app_toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

    <FrameLayout
        android:id="@+id/activityMainContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/colorPrimary"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:itemTextColor="@android:color/white"
        app:menu="@menu/activity_main_drawer" />

</RelativeLayout>

</android.support.v4.widget.DrawerLayout>
Moses answered 18/5, 2017 at 10:21 Comment(1)
Doing this will take my toolbar inside drawer i.e it will not be on top as in picture which is not my requirement. I want toolbar to stay on top above drawerlayout and open side drawer to full screen instead of half screen.Decay
V
0

This is how you can achieve it.

<android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:layout_marginEnd="-65dp"
        android:layout_marginRight="-65dp"
        android:fitsSystemWindows="true">
      />
Vendible answered 6/2, 2020 at 6:24 Comment(0)
M
0

In the main Drawerlayout class there is variable as private static final int MIN_DRAWER_MARGIN = 64;

So to make full drawer just give android:layout_marginStart="-64dp" to navigation view or the container where the drawer will be loaded.

Mindamindanao answered 12/6, 2020 at 13:1 Comment(0)
D
-2

Try changing android:layout_width="wrap_content" to android:layout_width="fill_parent"

and this should fix your issue, and let me know......

Dinin answered 18/5, 2017 at 10:24 Comment(2)
tried this solution, but it still not covering whole screen. Some portion is still left out.Decay
fill_parent is deprecated.Fife

© 2022 - 2024 — McMap. All rights reserved.