Skip to main content

Two Drawer Layouts from Same Side in Xamarin.Android

·107 words·1 min

In one of the projects, client require to built a design where a secondary drawer will opened over already opened primary drawer.

As per Android Material Design guidelines its not recommended and its not implemented in android.support.v4.widget.DrawerLayout. If we try to implement it in code like following, it throws exception, only one drawer can be shown.

{%highlight xml %}

<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.NavigationView android:id="@+id/first_nav_view" android:layout_width=“wrap_content” android:layout_height=“match_parent” android:layout_gravity=“start” android:fitsSystemWindows=“true” /> <android.support.design.widget.NavigationView android:id="@+id/second_nav_view" android:layout_width=“wrap_content” android:layout_height=“match_parent” android:layout_gravity=“start” android:fitsSystemWindows=“true” /> </android.support.v4.widget.DrawerLayout> {%endhighlight%}

To show both drawers from same side we need to extend the android.support.v4.widget.DrawerLayout to handle the navigation of secondary drawer over primary.