How to create a card toolbar using appcompat v7

后端 未结 2 1232
离开以前
离开以前 2020-12-02 15:04

I want to create a toolbar like the following image as proposed in the material design guidelines:

\"enter

2条回答
  •  鱼传尺愫
    2020-12-02 15:26

    You can obtain it using a Toolbar as ActionBar, a CardView and another Toolbar(standalone) inside the Card.

    For the Toolbar standalone inside a Card you can use something like this:

    
    
       
    
            
    
            //......
    
       
    
    
    

    Then you can inflate your menu to obtain the icon actions.

     Toolbar toolbar = (Toolbar) mActivity.findViewById(R.id.card_toolbar);
       if (toolbar != null) {
             //inflate your menu    
             toolbar.inflateMenu(R.menu.card_toolbar);
             toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem menuItem) {
                             //.....
                        }
                    });
       }
    

    For the toolbar used as action bar and the main layout you can use:

    option1:

    
    
          //Main toolbar 
    
        
    
         //described above
    
    
    

    Option2: An extended toolbar (as actionbar) and a CardView as described above playing with margins.

提交回复
热议问题