dynamic adding item to NavigationView in Android

后端 未结 3 700
一个人的身影
一个人的身影 2020-12-08 05:29

I want to build NavigationDrawer with the possibility of adding new items (such as yahoo weather App with adding new cities). I have working NavigationDra

3条回答
  •  佛祖请我去吃肉
    2020-12-08 05:31

    Suppose you have two groups, group1 and group2. If you want to dynamically add items to group1, then you can assign priority to group2 to make it always below group1. Then when you add new items to group1, it won't be inserted below group2.

    Here is a sample:

    
    
        
        
    
    

    And when you add menu items to group1:

    Menu menu = navigationView.getMenu();
    menu.add(R.id.group1,Menu.NONE,Menu.NONE,itemName);
    

    This should work. I tested it on Android design library 23.1.1.

提交回复
热议问题