Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add footer to Navigation Drawer in Android using design support library?

How can I add a footer to a NavigationView? In my case the NavigationView items are inflated by menu resource. Initially I tried to add a LinearLayout as a footer, but the NavigationView is not scrollable and the footer gets overlapped by the navigation menu items. I want to implement a Google Play rating segment as a footer exactly like this image:

enter image description here

navigation_drawer.xml:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">

  <android.support.v7.widget.Toolbar
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@color/colorPrimary"
      android:id="@+id/toolbar"
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
      app:title="@string/app_name" />

  <android.support.v4.widget.DrawerLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_height="match_parent"
      android:layout_width="match_parent"
      android:id="@+id/drawerLayout">

    <FrameLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/containerView">
    </FrameLayout>

    <android.support.design.widget.NavigationView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:id="@+id/shitstuff"
        app:itemTextColor="@color/green"
        app:menu="@menu/drawermenu"
        app:headerLayout="@layout/drawer_header"
        android:layout_marginTop="-24dp">
    </android.support.design.widget.NavigationView>

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

</LinearLayout>
like image 373
Shankha Jana Avatar asked Feb 18 '16 04:02

Shankha Jana


1 Answers

It's really simple:

just wrap the desired footer in your NavigationView. You can use mine as an example - works like a charm!

 <android.support.design.widget.NavigationView
    android:id="@+id/nvView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/white"
    app:headerLayout="@layout/navigation_header"
    app:itemTextColor="@android:color/black"
    app:menu="@menu/drawer_view">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:clickable="true"
        android:orientation="vertical">

        <TextView
            android:id="@+id/nav_footer_textview"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:gravity="center"
            android:text="Your Footer Text Here" />

    </LinearLayout>

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

You can use any (more or less complex) layout that way. (Afaik this footer won't scroll and will be fixed).

like image 129
Thkru Avatar answered Dec 24 '22 12:12

Thkru