在每个listview项目上添加“菜单”

时间:2021-01-30 07:32:01

I'm developing this app, which has a listview in it, but I want to add the "three-dot" icon in the corner, and when you press it, an awesome menu will popup. Like this in the Google Play app: http://imgur.com/a/cGb2Q

我正在开发这个应用程序,其中有一个列表视图,但我想在角落添加“三点”图标,当你按下它时,会弹出一个很棒的菜单。在Google Play应用中就像这样:http://imgur.com/a/cGb2Q

I've seen many apps that have it, so it could'nt be that hard? I have googled a lot, but to be honest, I don't know really what I should google on. This must probably be the shortest & dumbest question on *, but I didn't really know what my other options was.

我见过很多应用程序都有它,所以它可能不那么难?我已经google了很多,但说实话,我真的不知道我应该google什么。这可能是*上最短和最愚蠢的问题,但我真的不知道我的其他选择是什么。

I have a thought that it may just be an spinner that somehow is hidden and when you press the three-dot icon it'll just pop up in an awesome way, or is this implemented in the Android SDK?

我有一个想法,它可能只是一个微调器,以某种方式被隐藏,当你按下三点图标它只会弹出一个很棒的方式,或者这是在Android SDK中实现的?

2 个解决方案

#1


16  

I don't know how they do it or if this is the best way but you could create the overflow icon (3 dots) and use a PopupMenu for this. This was added in API 11 so it wouldn't work on older versions but if you are targeting API >= 11 then I think this would be a good option for you. I use it in a custom "actionbar".

我不知道他们是怎么做的,或者这是最好的方法,但你可以创建溢出图标(3个点)并使用PopupMenu。这是在API 11中添加的,因此它不适用于旧版本,但如果您的目标API> = 11,那么我认为这对您来说是个不错的选择。我在自定义的“操作栏”中使用它。

If this isn't awesome enough for you then you can also use PopupWindow which has been around since API 1

如果这对你来说不够好,那么你也可以使用自API 1以来一直存在的PopupWindow

PopupMenu

PopupWindow

#2


4  

I believe what you are looking for is a Popup Menu

我相信你要找的是弹出菜单

#1


16  

I don't know how they do it or if this is the best way but you could create the overflow icon (3 dots) and use a PopupMenu for this. This was added in API 11 so it wouldn't work on older versions but if you are targeting API >= 11 then I think this would be a good option for you. I use it in a custom "actionbar".

我不知道他们是怎么做的,或者这是最好的方法,但你可以创建溢出图标(3个点)并使用PopupMenu。这是在API 11中添加的,因此它不适用于旧版本,但如果您的目标API> = 11,那么我认为这对您来说是个不错的选择。我在自定义的“操作栏”中使用它。

If this isn't awesome enough for you then you can also use PopupWindow which has been around since API 1

如果这对你来说不够好,那么你也可以使用自API 1以来一直存在的PopupWindow

PopupMenu

PopupWindow

#2


4  

I believe what you are looking for is a Popup Menu

我相信你要找的是弹出菜单