Question

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. Can anybody tell me how to do this?

Was it helpful?

Solution

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.

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();
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top