android options menu always close

老子叫甜甜 提交于 2019-12-24 08:22:30

问题


I would like to know how to prevent the menu bar from closing.

@Override
public void onOptionsMenuClosed(Menu menu) {

}

When the activity starts I open the menu and want it to stay open.

    new Handler().postDelayed(new Runnable() {
        public void run() {
            openOptionsMenu();
        }
    }, 1000);

回答1:


You cannot keep the Options Menu open and it will always act that way. But what you can do is create your own custom menu in a layout.xml and set the visibility to GONE. Then, override the onKeyDown() method and listen for presses of the menu key. If it is pressed, the options menu will be set to open/close (VISIBLE/INVISIBLE) depending on its current state. That way, you can control if the options menu will remain open or not even after touch.



来源:https://stackoverflow.com/questions/7015024/android-options-menu-always-close

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!