Search code examples
androidandroid-recyclerviewmaterial-designandroid-toolbarandroid-cardview

Toolbar inside CardView to create a popup menu (overflow icon)


I have a list that looks like google play in a recyclerview with cardview, and works perfect.

I need to add a popup menu (with overflow icon), like this:

which is the best way to do this ?

I researched and found that there are 2 options:

1 - with a toolbar inside the cardview layout. is there a performanece problem with this solution ?

2 - with a imagebutton or imageview with a icon of the overflow, that when you click the menu is created.

I need a solution to be compatible with >= API 10

thanks


Solution

  • It depends by your layout.

    If you would like a layout like this, with a Toolbar you can achieve it more easily. enter image description here

    Somenthing like

    <android.support.v7.widget.CardView>
    
       <LinearLayout>
    
            <Toolbar  android:id="@+id/card_toolbar" />
    
            //......
    
       </LinearLayout>
    
    </CardView>
    
    toolbar.inflateMenu(R.menu.card_toolbar);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener(){..});
    

    If you would like only a popup is more simple to use an image. Somenthing like:

    PopupMenu popup = new PopupMenu(getContext(), mImageButton);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(......);