CardView 内的工具栏创建一个弹出菜单(溢出图标) [英] Toolbar inside CardView to create a popup menu (overflow icon)

查看:46
本文介绍了CardView 内的工具栏创建一个弹出菜单(溢出图标)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在带有 cardview 的 recyclerview 中有一个看起来像 google play 的列表,并且工作完美.

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:

最好的方法是什么?

我研究发现有两种选择:

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 - 带有一个带有溢出图标的图像按钮或图像视图,当你点击菜单时,就会创建.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆