1

I tried to add a footer to a drawer. It works but it remain fixed and it cover some menu item. How can I do to have the footer at the end of the list (after the last element). It takes the menu item from a xml (activity_main_drawer.xml) and it has a header (nav_header_main.xml)

The code of the drawer is this:

<?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">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <include
            layout="@layout/app_bar_main"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/side_nav_bar"
            android:id="@+id/content_main"/>
    </LinearLayout>
    <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:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer">
        <include layout="@layout/nav_footer_main"></include>
    </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

the code of footer (nav_footer_main.xml)

<?xml version="1.0" encoding="utf-8"?>
<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="@dimen/nav_footer_height"
    android:layout_alignParentBottom="true"
    android:layout_gravity="bottom"
    android:background="@drawable/side_nav_bar"

    android:baselineAligned="false"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:scaleType="centerCrop"
        app:srcCompat="@mipmap/copyright"
        tools:ignore="ContentDescription" />

    <TextView
        android:id="@+id/copyright"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/copyright" />
</LinearLayout>
mekki10
  • 33
  • 1
  • 8

2 Answers2

1

According to @Adreamus answer to the question How to add footer to NavigationView - Android support design library?

you could make it by 2 navigation views, look at this app example on Github

Also, I suggest you use MaterialDrawer Library it will save you a lot of time

enter image description here

Dasser Basyouni
  • 3,142
  • 5
  • 26
  • 50
0

You can add footer as an item in the menu of the navigation view like this menu_main:

<?xml version="1.0" encoding="utf-8"?>
<menu 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"
tools:showIn="navigation_view">

<group android:checkableBehavior="single">
    <item
        android:id="@+id/nav_home"
        android:icon="@drawable/ic_home"
        android:title="@string/home" />
    <item
        android:id="@+id/nav_about"
        android:icon="@drawable/ic_about_me"
        android:title="@string/about" />
</group>
<group>
    <item
        android:id="@+id/nav_footer"
        android:title=""
        app:actionLayout="@layout/nav_footer_main"
        app:showAsAction="never" />
</group>
</menu>

It will be scrollable and also easy to access from the code, you can use this:

val navigationFooter = navView.menu.findItem(R.id.nav_footer).actionView as View
    navigationFooter.findViewById<View>(R.id.btn_call_us).setOnClickListener {
        onCallButtonClicked()
    }

Good luck!

M.SH
  • 357
  • 2
  • 8
  • 22