Android的定制溢出菜单(无动作条和菜单按钮没有) [英] Android custom Overflow-menu (Without actionbar and no menubutton)

查看:88
本文介绍了Android的定制溢出菜单(无动作条和菜单按钮没有)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我已经作出了自己的动作条,以及它工作得很好。

In my application I have made my own Actionbar, and it works very well.

不过,我喜欢用的ICS-设备溢出按钮的行为,没有菜单按钮。

I would however like to use the behaviour of the overflow buttons on ICS-devices with no menu-button.

有没有办法来实现在ICS定制Overflowbutton是分开的动作条?

Is there a way to implement a custom Overflowbutton in ICS that is separate from the Actionbar?

谢谢!

推荐答案

userSeven7s大多与 ListPopupWindow ,但更好的贴合在这种情况下是<一个有它href="http://developer.android.com/reference/android/widget/PopupMenu.html"><$c$c>PopupMenu,它允许你吹一个标准的 menu.xml文件。你可以把自己的查看按钮在右上角和的onClick 处理程序创建并显示一个弹出菜单。

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. You can place your own View or Button in the upper right and in the onClick handler create and show a PopupMenu.

这是例子可以在ApiDemos>视图>弹出菜单中找到。特别是<一个href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/PopupMenu1.html"><$c$c>PopupMenu1.java:

An example can be found in ApiDemos > Views > Popup Menu . Specifically 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();
}

这篇关于Android的定制溢出菜单(无动作条和菜单按钮没有)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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