Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add item at bottom of navigation drawer

I'm a newbie on android studio and I've been trying to learn how to use the navigation drawer layout. I'm using the standard template for Nav Drawer, and wanted to add an item at the bottom of the menu, like this:

nav drawer image

at first i thought that the items in the drawer were inside a LinearLayout and it would be fairly easy to do what i want, but the xml code looks like this:

<?xml version="1.0" encoding="utf-8"?> 

<group android:checkableBehavior="single">     <item         android:id="@+id/nav_camera"         android:icon="@drawable/ic_menu_camera"         android:title="OP1" />     <item         android:id="@+id/nav_gallery"         android:icon="@drawable/ic_menu_gallery"         android:title="OP2" />     <item         android:id="@+id/nav_slideshow"         android:icon="@drawable/ic_menu_slideshow"         android:title="OP3" />     <item         android:id="@+id/nav_manage"         android:icon="@drawable/ic_menu_manage"         android:title="OP4" /> </group>   <group android:checkableBehavior="single">     <item         android:id="@+id/nav_logout"         android:title="Log out" /> </group> 

is there a way to make the group containing the logout item to be at the bottom? Thanks in advance for your answers!

like image 756
Avrgebro Avatar asked Aug 10 '17 22:08

Avrgebro


People also ask

How do I add a header to navigation?

In the Navigation pane, click the Headings tab. Do any of the following: To move part of the document, click the heading and drag it to a new location. To change the heading's level or add a heading, right-click the heading, and then choose the action you want.

How do I customize my navigation drawer?

Android App Development for BeginnersStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Step 3 − Add the following code to res/layout/nav_header_main.


1 Answers

Try this

Remove this part

<group android:checkableBehavior="single">     <item         android:id="@+id/nav_logout"         android:title="Log out" /> </group> 

then go to your layout where the navigation view is located.

<android.support.design.widget.NavigationView     android:id="@+id/navigationView"     android:layout_width="wrap_content"     android:layout_height="match_parent"     android:layout_gravity="start"     android:fitsSystemWindows="true"     app:headerLayout="@layout/nav_header_account_navigation"     app:menu="@menu/menu_lender_nav">      <LinearLayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_gravity="bottom"         android:orientation="vertical"         android:padding="16dp">          <TextView             android:id="@+id/logout"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:gravity="center"             android:text="Log out" />     </LinearLayout>  </android.support.design.widget.NavigationView> 
like image 177
Sakura Fukuyoshi Avatar answered Sep 22 '22 06:09

Sakura Fukuyoshi