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.

2
  • 1
    Is that your full menu file? Commented May 31, 2015 at 6:19
  • yes it is i have also my header as a layout and that's all Commented May 31, 2015 at 7:12

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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).

3 Comments

Yeah but the second problem is that he is showing only one item in the navigation drawer but i have two
@ouya, Did you make your menu xml file EXACTLY like what I posted above?
Yeah but the the action bar is hiding the other items

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.