• 3
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

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!

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>
  • 92
Reply Report
      • 1
    • Yes @Keselme, In my case if I take the smallest phone screen my list exceeds 4 items to be scrolled so I've added the dummy list item(with enabled = false property) at the end so it will occupy the space which is covered by the logout button at the end and a user can see all the items.
      • 1
    • In the case where you have multiple navigation items in that bottom list, how would you deal with them in code? It looks like you'd need to have event listeners for each extra item, and then have to coordinate the view state between items in the main list vs the ones on the bottom. Is there an easy way to leverage the fact that they're all children of a navigation menu and therefore treat them as menu items?