0

I want to make a menu with some section headers. But the source code in androidhive (http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/) is not supported it.

So how to add a section header (or make a menu item to be a section header) without change the whole source code ? Please help me!

Here's the screenshot, i want to make the "Lock", "Unlock" and "Learn" item to be the section header: https://i.stack.imgur.com/sk1zZ.png

Here's how I add item:

navDrawerItems = new ArrayList<NavDrawerItem>();


    // adding nav drawer items to array

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[8],0));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1)));       //, true, "22")); để thêm cái đuôi đằng sau

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[9],0));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1)));       //, true, "50+"));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[6], navMenuIcons.getResourceId(6, -1)));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[10], 0));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[7], navMenuIcons.getResourceId(7, -1)));

    // Recycle the typed array
    navMenuIcons.recycle();

UPDATE:

  • I can't use Material Design due to some personal reasons

  • What i need is Section Header. I did a "2 ListView in a Drawer and add Header in each ListView" but... yeah, it failed obviously!

Chris Maverick
  • 928
  • 1
  • 8
  • 18

3 Answers3

0

I recommend you to use this library: https://github.com/mikepenz/MaterialDrawer

Here you can implement your navigation drawer in less than 5 minutes.

You can find there configurations for Activities with ActionBar, implement right and left menus etc.

The basic configuration is:

Gradle dependency:

compile('com.mikepenz:materialdrawer:4.0.3@aar') {
    transitive = true
}

Add it to your Activity:

new DrawerBuilder().withActivity(this).build();

For advanced settings, you can follow the readme or taking a look to the given examples.

I hope this would help you!

Juan Aguilar Guisado
  • 1,687
  • 1
  • 12
  • 21
  • i actually did a Material Design NavigationView once. But now i can't use it! Any idea how to add Section Header without using Material Design? – Chris Maverick Aug 29 '15 at 10:03
0

You can create a menu_layout XML layout that contains ListView. Add this menu_layout XML layout in DrawerLayout. Now populate your menu in ListView programmatically. Now you can create a new header_layout XML. Add this header_layout programmatically in header view of ListView using addHeaderView() method.

Sagar Trehan
  • 2,401
  • 2
  • 24
  • 32
0

oh, i got the answer!

Just add isEnabled() - false and change the layout at the specific positions in the adapter.

And my menu item changed to section header!

Chris Maverick
  • 928
  • 1
  • 8
  • 18