3

I am using Navigation Drawer menu without the header. The first item in the menu is too close to the top bar. How can I create margin for the first item? I am using this drawer menu:

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

<item android:title="Home"
    android:id="@+id/nav_item_home"
    android:icon="@drawable/ic_home_black_24dp"/>

<item android:title="Search Definitions"
    android:id="@+id/nav_item_search"
    android:icon="@drawable/ic_search_black_24dp"/>

<item android:title="About">

    <menu>
        <item android:title="About this app"
            android:id="@+id/nav_item_about"
            android:icon="@drawable/ic_info_black_24dp"/>

        <item android:title="How to use this app"
            android:id="@+id/nav_item_howtouse"
            android:icon="@drawable/ic_perm_device_information_black_24dp"/>
    </menu>

</item>

The outcome is this:

First item in the navigation drawer is too close to the action bar

What I did as a workaround is to wrap the first item in a item menu with a blank title ... like this:

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

<item android:title="">
    <menu>
        <item android:title="Home"
            android:id="@+id/nav_item_home"
            android:icon="@drawable/ic_home_black_24dp"/>

        <item android:title="Search Definitions"
            android:id="@+id/nav_item_search"
            android:icon="@drawable/ic_search_black_24dp"/>
    </menu>
</item>

<item android:title="About">

    <menu>
        <item android:title="About this app"
            android:id="@+id/nav_item_about"
            android:icon="@drawable/ic_info_black_24dp"/>

        <item android:title="How to use this app"
            android:id="@+id/nav_item_howtouse"
            android:icon="@drawable/ic_perm_device_information_black_24dp"/>
    </menu>

</item>

And then the outcome is exactly what I wanted:

Desired Output

Can someone please confirm if this workaround is the only way or is there any correct way of achieving the desired output.

Naveen Chand K
  • 411
  • 1
  • 5
  • 13
  • https://stackoverflow.com/questions/39913570/how-to-overcome-this-item-padding-in-navigation-drawer Answered her by deadfish – Goodlife Jul 20 '17 at 15:02

1 Answers1

1

Bit late, but any solution?

I've just played around in the xml:

<android.support.design.widget.NavigationView>
...
android:layout_marginTop="?attr/actionBarSize"
android:paddingTop="somePaddingValueInSp"
...
/>
BenRoob
  • 1,662
  • 5
  • 22
  • 24