DPaselli
DPaselli

Reputation: 264

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

Upvotes: 8

Views: 5197

Answers (3)

Farshad Molazeinali
Farshad Molazeinali

Reputation: 86

I solve it with the help of constraint layout

I solve it this way

Upvotes: 0

Arnold Brown
Arnold Brown

Reputation: 1433

Try this!

In your menu/activity_main_drawer

Add the following after the group

<item android:title="">
    <menu>
        <item
            android:id="@+id/nav_about_us"
            android:title="Follow us:"
            app:actionLayout="@layout/share"
            app:showAsAction="ifRoom"/>
    </menu>
</item>

and your_custom_layout.xml may be like

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:orientation="vertical"
    android:background="@color/colorPrimaryDark">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center">

       <ImageButton
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:src="@drawable/right_arrow"/>

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/right_arrow"/>

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/right_arrow"/>

    </LinearLayout>

</LinearLayout>

Upvotes: 2

Vasily Kabunov
Vasily Kabunov

Reputation: 6761

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>

Upvotes: 8

Related Questions