CardView内部的工具栏,用于创建弹出菜单(溢出图标) [英] Toolbar inside CardView to create a popup menu (overflow icon)
问题描述
我有一个列表,看起来像是Google在带有cardview的recyclerview中播放,并且效果很好.
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:
这是最好的方法吗?
我研究发现,有2种选择:
I researched and found that there are 2 options:
1-在Cardview布局内有一个工具栏.此解决方案存在性能问题吗?
1 - with a toolbar inside the cardview layout. is there a performanece problem with this solution ?
2-使用带有溢出图标的imagebutton或imageview, 单击菜单即会创建.
2 - with a imagebutton or imageview with a icon of the overflow, that when you click the menu is created.
我需要一种与> = API 10兼容的解决方案
I need a solution to be compatible with >= API 10
谢谢
推荐答案
这取决于您的布局.
如果您想要这样的布局,可以使用工具栏更轻松地实现它.
If you would like a layout like this, with a Toolbar you can achieve it more easily.
像这样
<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(......);
这篇关于CardView内部的工具栏,用于创建弹出菜单(溢出图标)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!