[英]Android custom Overflow-menu (Without actionbar and no menubutton)
In my application I have made my own Actionbar, and it works very well. 在我的应用程序中,我制作了自己的Actionbar,并且效果很好。
I would however like to use the behaviour of the overflow buttons on ICS-devices with no menu-button. 但是,我想在没有菜单按钮的ICS设备上使用溢出按钮的行为。
Is there a way to implement a custom Overflowbutton in ICS that is separate from the Actionbar? 有没有办法在ICS中实现与操作栏分开的自定义Overflowbutton?
Thanks! 谢谢!
userSeven7s mostly has it with the ListPopupWindow
, but an even better fit in this case is the PopupMenu
, which allows you to inflate a standard menu.xml
. userSeven7s大多与
ListPopupWindow
,但是在这种情况下更合适的是PopupMenu
,它允许您膨胀标准的menu.xml
。 You can place your own View
or Button
in the upper right and in the onClick
handler create and show a PopupMenu. 您可以在右上角放置自己的“
View
或“ Button
,并在onClick
处理程序中创建并显示PopupMenu。
An example can be found in ApiDemos > Views > Popup Menu . 可以在ApiDemos>“视图”>“弹出菜单”中找到一个示例。 Specifically
PopupMenu1.java
: 特别是
PopupMenu1.java
:
public void onPopupButtonClick(View button) {
PopupMenu popup = new PopupMenu(this, button);
popup.getMenuInflater().inflate(R.menu.popup, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(PopupMenu1.this, "Clicked popup menu item " + item.getTitle(),
Toast.LENGTH_SHORT).show();
return true;
}
});
popup.show();
}
Have you looked at ActionBar Sherlock? 您看过ActionBar Sherlock吗? ABS provides action bar support for all devices running android 2.1 and above.
ABS为所有运行android 2.1及更高版本的设备提供动作栏支持。 The ActionBarCompat sample is very limited and does not support overflow menus on older devices.
ActionBarCompat示例非常有限,并且不支持旧设备上的溢出菜单。 Be sure to use the Theme.Sherlock.ForceOverflow theme to enable overflow.
确保使用Theme.Sherlock.ForceOverflow主题来启用溢出。
http://actionbarsherlock.com/ http://actionbarsherlock.com/
You could also modify the QuickAction library to do what you want. 您还可以修改QuickAction库以执行所需的操作。
https://github.com/lorensiuswlt/NewQuickAction https://github.com/lorensiuswlt/NewQuickAction
You could slide/scroll your action bar to let access to more options. 您可以滑动/滚动操作栏以访问更多选项。 Put your action bar in a
HorizontalScrollView.
将操作栏放在
HorizontalScrollView.
You might also want to take a look at PopupWindow
class here , and ListPopupWindow
documentation here . 你可能也想看看
PopupWindow
类在这里 ,和ListPopupWindow
文档在这里 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.