0

I'm doing this in my layout :

<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_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

    <!-- your content layout -->

    <android.support.design.widget.NavigationView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:headerLayout="@layout/drawer_header"
            app:menu="@menu/drawer"/>
</android.support.v4.widget.DrawerLayout>

and this in my menu :

<item
    android:id="@+id/navigation_subheader"
    android:title="@string/navigation_subheader">
    <menu>
        <item
            android:id="@+id/navigation_sub_item_1"
            android:icon="@drawable/ic_android"
            android:title="@string/navigation_sub_item_1"/>
        <item
            android:id="@+id/navigation_sub_item_2"
            android:icon="@drawable/ic_android"
            android:title="@string/navigation_sub_item_2"/>
    </menu>
</item>

First problem if I do this I can't see all the elements of the navigation drawer. Second problem if I want to add an header I can see it.For the header I'm only puttin a relative alyout who have a red background.

Dhanuka
  • 2,826
  • 5
  • 27
  • 38
ouya
  • 213
  • 1
  • 3
  • 10

2 Answers2

1

Problem #1

Your menu needs to have <menu> as the root element, like this:

<menu>
    <item
        android:id="@+id/navigation_item_1"
        android:icon="@drawable/ic_android"
        android:title="@string/navigation_item_1"/>
    <item
        android:id="@+id/navigation_item_2"
        android:icon="@drawable/ic_android"
        android:title="@string/navigation_item_2"/>
</menu>

If you really want to use submenus, then place another <menu> inside of a top-level <item>. See Menu Resource for more info on how to nest these elements.

Problem #2

Check your layout_width and layout_height. Also, make sure it displays correctly in your IDE layout editor first.

Update:

If your navigation drawer is drawing underneath your action bar (like you mentioned in the comments), it's related to your layout, not your menu items. Please post how you are creating your action bar (either in code or in xml).

hungryghost
  • 9,463
  • 3
  • 23
  • 36
1

First problem if I do this I can't see all the elements of the navigation drawer.

If I understand correctly you at least see one item right? Could you try to use this instead:

<group android:checkableBehavior="single">
    <item
        android:id="@+id/navigation_item_1"
        android:checked="true"
        android:icon="@drawable/ic_android"
        android:title="@string/navigation_item_1"/>
    <item
        android:id="@+id/navigation_item_2"
        android:icon="@drawable/ic_android"
        android:title="@string/navigation_item_2"/>
</group>

See if this works. Most Navigation Drawers begin with the navigation items (the group as seen above) and below use a sub header for grouped items.

Second problem if I want to add an header I can see it.For the header I'm only puttin a relative alyout who have a red background.

You need to set a height for this header layout (or a minHeight). Now it doesn't know how big it needs to be.

If you want a sample project you can take a look at the sample project provided by Chris Banes: https://github.com/chrisbanes/cheesesquare

Kevin van Mierlo
  • 9,554
  • 5
  • 44
  • 76