简体   繁体   English

如何在Android设备中显示菜单按钮单击的操作栏菜单

[英]How to show action bar menu for menu button click in android device

I have implemented the action bar in my application. 我已经在应用程序中实现了操作栏。 I have implemented the action bar menu using a support library. 我已经使用支持库实现了操作栏菜单。 I want to show the same menu while clicking a menu button on an android device. 我想在Android设备上单击菜单按钮时显示相同的菜单。 Can anybody tell me how to do this? 有人可以告诉我该怎么做吗?

I can get you as far as detecting the menu key. 我可以帮助您检测菜单键。 Depending on device there may be overflow of actionbar menu that appears when the menu key is pressed. 取决于设备,按菜单键时可能会出现操作栏菜单溢出。 There are a lot more questions for a complete answer it might be as simple as building the menu options programmatically versus using a res/menu/menu.xml file. 一个完整的答案还有很多问题,这可能就像通过编程来构建菜单选项而不是使用res / menu / menu.xml文件那样简单。

Below I force full screen in an app when the menu key is pressed. 在下面,当我按下菜单键时会在应用程序中强制全屏显示。

@Override
    public boolean onKeyDown(int keycode, KeyEvent e) {
        switch (keycode) {
        // show the bar if the menu button is pressed
        case KeyEvent.KEYCODE_MENU:
            isFullScreen = false;
            this.setFullScreen(isFullScreen);
            return false;
        }
        return super.onKeyDown(keycode, e);
    }


@Override
    public void setFullScreen(boolean isChecked) {
        if (!isChecked) {
            if (Build.VERSION.SDK_INT < 16) {
                getWindow().clearFlags(
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }
            bar.show();
        } else {
            if (Build.VERSION.SDK_INT < 16) {
                getWindow()
                        .addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }
            bar.hide();
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM