-1

I have an app with drawer menu. The apps architecture requires menu items to be created dynamically, so they appers to look according to matherial design standards.

Here is the code, that creates menu.

     private void formMainMenu() {
        itemsByGroups = getMenuItemGroups();
        Menu menu = navigationView.getMenu();
        int groupId = 0;
        for (Map.Entry<String, List<MainMenuUser>> entry : itemsByGroups.entrySet()) {
            if (!entry.getKey().equals(MainMenuGroup.TOP.toString()) &&
                    !entry.getKey().equals(MainMenuGroup.BOTTOM.toString())) {
                createSubmenu(menu, groupId, entry);
            } else {
                createMenuItem(menu, groupId, entry);
            }
            groupId++;
        }
    }

    private void createSubmenu(Menu menu, int groupId, Map.Entry<String, List<MainMenuUser>> entry) {
        String subMenuHeader = entry.getKey();
        SubMenu subMenu = menu.addSubMenu(groupId, Menu.NONE, Menu.NONE, subMenuHeader);

        List<MainMenuUser> menuUsers = entry.getValue();
        for (int i = 0; i < menuUsers.size(); i++) {
            int order = menuUsers.get(i).getMainMenuPositionOrder();
            int titleId = menuUsers.get(i).getMainMenuItem().getTitleId();
            if (menuUsers.get(i).isEnableNow(BaseApp.getApp().getSdkConfig().getSupportedFunctionality())) {
                subMenu.add(groupId, i, order, titleId);
            }
        }
    }

    private void createMenuItem(Menu menu, int groupId, Map.Entry<String, List<MainMenuUser>> entry) {

        List<MainMenuUser> menuUsers = entry.getValue();
        for (int i = 0; i < menuUsers.size(); i++) {
            if (menuUsers.get(i).isEnableNow(BaseApp.getApp().getSdkConfig().getSupportedFunctionality())) {
                menu.add(groupId, i, Menu.NONE, menuUsers.get(i).getMainMenuItem().getTitleId());
            }
        }
    }

And this is how it looks.

enter image description here

My question. What is the way to customize headers and items using styles, maybe, to be able change drawer appearance depending on product flavour?

Dmitry Smolyaninov
  • 2,159
  • 1
  • 18
  • 32
  • 1
    hehe this is 1.000.000th question tagged `android`... now you should try your good luck on the lottery ;-) – pskink Jun 21 '17 at 11:09

1 Answers1

1

I think it will be easier for you to use a ListView or a RecylerView there.

This question may give you some insights how to do it.