How to programmatically add a submenu item to the new material design android support library

前端 未结 5 1573
时光说笑
时光说笑 2020-11-28 23:26

I am trying to add new menu items to a submenu in the new Material Design drawer panel.



        
5条回答
  •  失恋的感觉
    2020-11-29 00:12

    This is how I manipulate the sub-menu item in NavigationView

    1) Create menu.xml file

    
    
      
        
          
    
            
            
    
          
        
      
    
      
        
        
                
          
          
        
        
      
        
    

    2) Manipulate the menu by calling this function

            /// 
        /// 
        /// 
        /// 
        private void AddNavigationMenuItem (NavigationView navView)
        {
            navView.Menu.FindItem(Resource.Id.mnugrp_Index).SubMenu.Clear();
            navView.Menu.FindItem(Resource.Id.mnugrp_Index).SubMenu.Add("This is Index 1");
            navView.Menu.FindItem(Resource.Id.mnugrp_Index).SubMenu.Add("This is Index 2");
            navView.Menu.FindItem(Resource.Id.mnugrp_Index).SubMenu.Add("This is Index 3");
            navView.Menu.FindItem(Resource.Id.mnugrp_Index).SubMenu.Add("This is Index 4");
    
            navView.Menu.FindItem(Resource.Id.mnugrp_Attachment).SubMenu.Clear();
            navView.Menu.FindItem(Resource.Id.mnugrp_Attachment).SubMenu.Add("This is Attachment 1");
            navView.Menu.FindItem(Resource.Id.mnugrp_Attachment).SubMenu.Add("This is Attachment 2");
            navView.Menu.FindItem(Resource.Id.mnugrp_Attachment).SubMenu.Add("This is Attachment 3");
            navView.Menu.FindItem(Resource.Id.mnugrp_Attachment).SubMenu.Add("This is Attachment 4");
        }
    

提交回复
热议问题