How to add checkbox to material navigation drawer?

前端 未结 4 938
醉梦人生
醉梦人生 2020-12-14 20:59

I use Menu items Icon Menu but I want to add checkbox to all menu item. This is my drawer_menu.xml



        
4条回答
  •  抹茶落季
    2020-12-14 21:55

    With app:actionLayout you can make miracles happen.

    Here's an example achieving custom widgets in drawer without any Java code:

    
        
    
    

    menu/widgets.xml

    
    
        
            
                
                
                
                
                
                
                
            
        
    
    

    All the layouts (each is a single file)

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        

    Connecting with code

    You can access it just like any other menu:

    // 
    NavigationView nav = (NavigationView)findViewById(R.id.navigation_view);
    MenuItem switchItem = nav.getMenu().findItem(R.id.switch);
    CompoundButton switchView = (CompoundButton)MenuItemCompat.getActionView(switchItem);
    switchView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { }
    });
    

提交回复
热议问题