0

enter image description hereI have a navigation drawer made using drawer layout and adapter. I want to add a logout button at the bottom of the side menu. I went through SO, but couldn't solve. The main xml file has a list view in a drawer layout.

         <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.DrawerLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
   android:layout_width="match_parent"
   android:layout_height="match_parent">

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical"
    android:weightSum="5"
     <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1.5"></LinearLayout>

   <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:layout_gravity="center"
    android:orientation="vertical">

        <Button
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@drawable/buttonbackground"
        android:text="PHOTOS"
        android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
        android:textColor="@color/white" />

        <Button
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        android:background="@drawable/buttonbackground"
        android:text="VIDEOS"
        android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
        android:textColor="@color/white" />

        <Button
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        android:background="@drawable/buttonbackground"
        android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
        android:text="HISTORY"
        android:textColor="@color/white" />

        </LinearLayout>
        <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="0dp"
        android:layout_weight="1.5"></LinearLayout>

         </LinearLayout>

        <RelativeLayout
         android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView
        android:id="@+id/navList"
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:layout_above="@+id/logout"
        android:layout_gravity="left|start"
        android:background="#ffeeeeee"></ListView>

        <Button
        android:id="@+id/logout"
        android:layout_width="320dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="LogOut" />
         </RelativeLayout>
         </android.support.v4.widget.DrawerLayout>
        <android.support.v4.widget.DrawerLayout/>

And the list is being inflated in the java code.

     private void addDrawerItems() {
    String items[]={"Home","Video","Camera","History","Version"};
    mAdapter=new ArrayAdapter<>(this,R.layout.listview_drawer_item_row,items);
    mDrawerList.setAdapter(mAdapter);
}

How do I add a button at the bottom of the menu?

Hardik Mehta
  • 867
  • 1
  • 12
  • 20
Harshita
  • 382
  • 1
  • 6
  • 21

2 Answers2

0

Can you try this, Its a work around but I hope it'll give some idea to solve your issue

 <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="left|start">
        <ListView
            android:id="@+id/navList"
            android:layout_width="320dp"
            android:layout_height="match_parent"
            android:layout_above="@+id/logout"
            android:layout_gravity="left|start"
            android:background="#ffeeeeee"></ListView>

        <Button
            android:id="@+id/logout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="LogOut" />
    </RelativeLayout>
Raghavendra
  • 2,305
  • 25
  • 30
0

As per my experience and knowledge you need to add your logout button as footerview of your listview or either set it to bottom in your navigation view. You can't place your button outside of your navigationView. If you manage to achieve something like that you will be only able to scroll your navigation view not your logout button. I assume it won't scroll with your navigationView.

For this to achieve, make a custom layout as per your requirement and set as a footerview or either set it in bottom of your navigationView.

AndiM
  • 2,196
  • 2
  • 21
  • 38