Itiel Maimon Itiel Maimon - 5 months ago 9
Java Question

How to add some space under the last item in a Navigation Drawer?

I have a Navigation Drawer that contains several items.
I added a button on the bottom of the Navigation Drawer.
The problem is that in small size screens the button covers the last item in the Drawer.

How can I add some space under the last item so the button won't cover anything?

activity_main.xml:

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

<Button
android:id="@+id/remove_ads_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/red"
android:text="@string/remove_ads"
android:textColor="@color/white"
android:textSize="15sp" />

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

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


activity_main_drawer.xml:

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

<group android:checkableBehavior="none">
<item
android:id="@+id/action_contact_us"
android:icon="@drawable/ic_contact_us"
android:title="@string/action_contact_us" />
<item
android:id="@+id/action_share"
android:icon="@drawable/ic_share_24dp"
android:title="@string/action_share" />
<item
android:id="@+id/action_rate_us"
android:icon="@drawable/ic_rate_us_24dp"
android:title="@string/action_rate_us" />
<item
android:id="@+id/action_follow_us"
android:icon="@drawable/ic_follow_us_24dp"
android:title="@string/action_follow_us" />
<item
android:id="@+id/action_help"
android:icon="@drawable/ic_help_name"
android:title="@string/action_help" />
<item
android:id="@+id/action_about_us"
android:icon="@drawable/ic_info_24dp"
android:title="@string/action_about_us" />
<item
android:id="@+id/action_settings"
android:icon="@drawable/ic_settings_24dp"
android:title="@string/action_settings" />
</group>

</menu>

Answer

I came up with an idea how to do it and it worked for me. What I needed to do is to add one more Item to the Drawer and then disable it.

The code is:

 <item
    android:title=""
    android:enabled="false" >
</item>

Very simple and easy!!!

Comments