Two navigation boxes with the same activity

Is it possible to configure two navigation boxes for the same activity, one on the left and the other on the right?

+9
android navigation-drawer
source share
4 answers

You can use the box layout

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- The main content view --> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> <!-- The navigation drawer --> <ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="#111"/> <ListView android:id="@+id/right_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="end" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="#111"/> </android.support.v4.widget.DrawerLayout> 

ALSO check the documentation https://developer.android.com/training/implementing-navigation/nav-drawer.html

Make sure you use the toolbar and not the action bar

+11
source share

Yes, you can add two types of ListView to your box layout, one list should have gravity start , and the other should have end .

+3
source share

Yes

You can use two navigation windows

 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/drawer_layout" tools:context="PackageName.ActivityName"> <ScrollView android:id="@+id/scrol_lay" android:layout_width="match_parent" android:layout_height="wrap_content"> <!-- your layout --> </ScrollView> <!-- First navigation drawer --> <android.support.design.widget.NavigationView android:id="@+id/navigation_view_main" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" app:menu="@menu/navigation_main_menu" app:headerLayout="@layout/navigation_header"/> <!-- Second navigation drawer --> <android.support.design.widget.NavigationView android:id="@+id/navigation_view_second" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="end" app:menu="@menu/navigation_menu" app:headerLayout="@layout/navigation_header"/> </android.support.v4.widget.DrawerLayout> 
+2
source share

For maximum customization, In your xml you can use FrameLayout as a container

  <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:fitsSystemWindows="true"> <FrameLayout android:id="@+id/contDrawer" android:layout_width="match_parent" android:layout_height="match_parent" /> </android.support.design.widget.NavigationView> 

Now in your activity you can replace it with any fragment

 getSupportFragmentManager().beginTransaction().replace(R.id.contDrawer, SideBarCustomerFragment.newInstance()).commit(); 

Now for two users you can create 2 different fragments. You can check my boilerplate code for reference.

https://github.com/hamzaahmedkhan/AndroidStructure/blob/master/app/src/main/java/com/android/structure/activities/HomeActivity.java

https://github.com/hamzaahmedkhan/AndroidStructure/blob/master/app/src/main/java/com/android/structure/activities/BaseActivity.java

0
source share

All Articles