如何在没有操作栏的情况下添加菜单按钮? [英] How to add menu button without action bar?

查看:90
本文介绍了如何在没有操作栏的情况下添加菜单按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序的右上角添加一个菜单按钮,并且没有操作栏,就像下面屏幕截图中的Google Fit应用程序中一样. 谁能帮我吗?

I'd like to add a menu button to the right top corner of my app and without action bar, like it is in Google Fit app on the screenshot below. Can anyone help me?

推荐答案

您可以简单地使用PopupMenu,例如在单击按钮时将以下内容添加到按钮中:

You can simply use PopupMenu, for example add the following to a button when clicked:

public void showPopup(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.actions, popup.getMenu());
    popup.show();
}

有关更多信息,请阅读Creating a Popup Menu: http://developer.android.com/guide/topics/ui/menus.html

For more info, read Creating a Popup Menu : http://developer.android.com/guide/topics/ui/menus.html

这篇关于如何在没有操作栏的情况下添加菜单按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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