Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add buttons in a drawer menu's footer

I would like to add those buttons under a drawer menu

drawerMenu

those are my xml files:

(layout/activity_main)

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <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"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

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

(menu/activity_main_drawer)

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group
        android:checkableBehavior="single">
        <item
            android:id="@+id/nav_log"
            android:title="Log-in" />
        <item
            android:id="@+id/nav_preferiti"
            android:title="Preferiti" />
        <item
            android:id="@+id/nav_maps"
            android:title="Mappa" />
        <item
            android:id="@+id/nav_terms"
            android:title="Termini e condizioni" />
        <item
            android:id="@+id/nav_who"
            android:title="Chi Siamo" />
        <item
            android:id="@+id/nav_settings"
            android:title="Impostazioni" />
        <item
            android:id="@+id/nav_tutorial"
            android:title="Tutorial" />
    </group>

</menu>

I tried to use a linearlayout with gravity bottom (or end) but it remained at the top

like image 850
DPaselli Avatar asked Apr 21 '16 09:04

DPaselli


People also ask

How do I add a footer in navigation drawer?

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

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 to place additional views inside your NavigationView, something like:

<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"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer">


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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true">

            <!--Here is a container at the bottom of navigation drawer. Place your images here-->

        </LinearLayout>

    </RelativeLayout>

</android.support.design.widget.NavigationView>
like image 185
Vasily Kabunov Avatar answered Oct 11 '22 14:10

Vasily Kabunov