dev90
dev90

Reputation: 7519

How to open side navigation in full screen

I have added navigation drawer in my app, and it opens like following

enter image description here

But i want to open the drawer to full width like following.

enter image description here

I checked some answers on SO, and set margin to -64dp but that didn't help, is it possible to set width of navigation drawer to full screen.

Upvotes: 0

Views: 728

Answers (5)

Marium Jawed
Marium Jawed

Reputation: 419

try this code:

<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">
      />

Upvotes: 0

Bhavik Nathani
Bhavik Nathani

Reputation: 499

Set full width navigation drawer in android

Just call this method and pass your drawerlayout as parameter.

public static void fixDrawerMargin(DrawerLayout drawerLayout) {
        try {
            Field f = DrawerLayout.class.getDeclaredField("mMinDrawerMargin");
            f.setAccessible(true);
            f.set(drawerLayout, 0);

            drawerLayout.requestLayout();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Upvotes: 0

UD..
UD..

Reputation: 80

try this!!! work perfectly

<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" />

Upvotes: 1

Farhan Fahim
Farhan Fahim

Reputation: 137

just add this code in your Navigation View that's it

android:layout_gravity="start"
android:fitsSystemWindows="true"
android:layout_marginEnd="-65dp"
android:layout_marginRight="-65dp"

Upvotes: 2

Md Mobinur Rahman
Md Mobinur Rahman

Reputation: 395

You can try this

<android.support.design.widget.NavigationView
        android:id="@+id/navigationView"
        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:itemTextAppearance="@style/TextAppearance.AppCompat.Small"
        app:headerLayout="@layout/drawer_header">

Upvotes: 1

Related Questions