简体   繁体   中英

Add a section header in ListView Menu

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: http://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!

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!

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM