How to add footer buttons in NavigationView

Sandro Simas picture Sandro Simas · Oct 22, 2015 · Viewed 10.8k times · Source

I'm following the post "Android design library NavigationView with footer" to add buttons at the bottom of NavigationView. The problem is that only the last NavigationView appears and it's occuping the entire screen height.

Here is my layout:

<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">

    <!-- Activity here -->

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start">

        <android.support.design.widget.NavigationView
            android:id="@+id/navigation_menu_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="top"
            app:menu="@menu/menu_drawer"/>

        <android.support.design.widget.NavigationView
            android:id="@+id/navigation_footer_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:menu="@menu/menu_drawer_footer"/>

    </android.support.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>

Here is the result:

enter image description here

How can i fix this?

Answer

Mohammed Fadhl picture Mohammed Fadhl · Jul 20, 2016

The simplest answer is to add a button inside the Drawer layout and set it gravity to bottom in the navigationview.xml

as easy as that !!! here is the code.

<android.support.design.widget.NavigationView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/navigation"
    android:layout_width="200dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/navigation_header"
    app:menu="@menu/menu_navigation"
    android:layout_alignParentTop="true">

   <Button
        android:id="@+id/btn_sing_in"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="@string/sign_in"
        android:layout_gravity="bottom"
       />
</android.support.design.widget.NavigationView>

add button inside Drawer layour