在 android 2.x 中像在 ICS 中一样创建下拉菜单的最佳方法 [英] The best way to create drop down menu in android 2.x like in ICS

查看:24
本文介绍了在 android 2.x 中像在 ICS 中一样创建下拉菜单的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建带有下拉菜单的按钮,例如 ICS 上 ActionBar 中的溢出菜单按钮.我有问题,因为 android 2.x 中没有 PopupMenu.第二种使用 Spinner 的方式,但它不适合我,因为 Spinner 总是在我的自定义背景或我选择的项目上显示第一个项目.我怎样才能实现它?一般来说,我想要 ContextMenu 但很少和位置点击视图.谢谢.

I want to create button with drop down menu, like overflow menu button in ActionBar on ICS. I have problem because PopupMenu there isn't in android 2.x. The second way using Spinner but it's not for me, because Spinner always show the first item on my custom background or my selected item. How can I acheive it? In general, I want ContextMenu but little and on position clicked view. Thanks.

它看起来像这样:

推荐答案

如果您的目的是重新创建操作栏,您可以查看 ActionBarSherlock 项目,该项目向后移植这些功能.

If your purpose is to recreate an action bar, you could take a look at the ActionBarSherlock project, which backports thoses functionalities.

如果您希望能够在应用程序的任何位置弹出这样的菜单,您可以阅读 MenuPopupHelper 类在 中的实现ActionBarSherlock 项目源代码.

If you want to be able to pop such a menu anywhere in your app, you could read the implementation of the MenuPopupHelper class implementation in the ActionBarSherlock project source code.

这篇关于在 android 2.x 中像在 ICS 中一样创建下拉菜单的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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