How do I add a title to my menu group

后端 未结 6 1770
名媛妹妹
名媛妹妹 2021-02-02 08:25

I want to differentiate the groups by giving them a title or divider, but I can\'t find a title option for the group element.

Is there a way to add a title or divider?

6条回答
  •  青春惊慌失措
    2021-02-02 09:05

    Although that might not be the best approach, I believe it might help you out. What about you add extra disabled itens as "titles" inside the groups, also you could create a style for those itens so they might show the color you want.

     
        
            
                
                
                
                
                
                
                
                
            
            
                
                
    
                
                
                
                
            
        
    

    You also can try something like that, using java.

    @Override
        public boolean onCreateOptionsMenu(Menu menu) {
    
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            menu.addSubMenu(Menu.NONE, 1, 1, "SubMenu");
            menu.add(1, 2, 2, "Item");
            menu.add(1, 3, 3, "Item");
    
            menu.addSubMenu(Menu.NONE, Menu.NONE, 4, "SubMenu");
            menu.add(4, 5, 5, "Item");
            menu.add(4, 6, 6, "Item");
            menu.add(4, 7, 7, "Item");
    
            return true;
        }
    

    Parameters

    • groupId The group identifier that this item should be part of. This can also be used to define groups of items for batch state changes. Normally use NONE if an item should not be in a group.
    • itemId Unique item ID. Use NONE if you do not need a unique ID.
    • order The order for the item. Use NONE if you do not care about the order. See getOrder().
    • title The text to display for the item.

    Yet, I believe both should have the same result.

    I hope it help you.

提交回复
热议问题