为什么OnOptionsMenuClosed不叫在Android [英] Why OnOptionsMenuClosed not called on Android

查看:342
本文介绍了为什么OnOptionsMenuClosed不叫在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有必要隐藏的ActionBar退出菜单后。要捕获在活动截止重写onOptionsMenuClosed(菜单菜单)。但菜单是封闭的,不调用此方法。而不是当我点击返回或触摸时通过菜单。如何解决呢?

这是在Main.java我的code:

  @覆盖
公共布尔onCreateOptionsMenu(菜单菜单){
    super.onCreateOptionsMenu(菜单);
    。getMenuInflater()膨胀(R.menu.menu_fomenu,菜单);
    返回true;
}@覆盖
公共布尔onOptionsItemSelected(菜单项项){
    INT ID = item.getItemId();    如果(ID == R.id.default_lista_betoltese){
        Toast.makeText(getApplicationContext(),
                Alaplistabetöltésekész
                Toast.LENGTH_SHORT)
                。显示();
        返回true;
    }    如果(ID == R.id.lista_betoltese){
        Toast.makeText(getApplicationContext(),
                Mentett LISTAbetöltésekész
                Toast.LENGTH_SHORT)
                。显示();
        返回true;
    }    如果(ID == R.id.lista_mentese){
        Toast.makeText(getApplicationContext(),
                Mentéskész
                Toast.LENGTH_SHORT)
                。显示();
        返回true;
    }    如果(ID == R.id.szerkeszto_mod){
        szerkeszto_mod(szerkesztomod!);
        返回true;
    }    如果(ID == R.id.betumeret_noveles){
        betumeret ++;
        Toast.makeText(getApplicationContext(),
                Betűméret:+ betumeret,
                Toast.LENGTH_SHORT)
                。显示();
        返回true;
    }    返回super.onOptionsItemSelected(项目);
}@覆盖
公共无效onOptionsMenuClosed(菜单菜单){
    super.onOptionsMenuClosed(菜单);
    getWindow()。getDecorView()。setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
                    View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}


解决方案

使用ActionBar.OnMenuVisibilityListener为当显示或操作栏菜单接收事件隐藏的。

http://developer.android.com/reference/android/app/ActionBar.OnMenuVisibilityListener.html

It is necessary to hide the ActionBar after you exit the menu. To trap closing Overriding onOptionsMenuClosed (Menu menu) in the Activity. But the menu is closed, this method is not invoked. And not when I click "back" or when touch by the menu. How to fix it?

This is my code in Main.java:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.menu_fomenu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.default_lista_betoltese) {
        Toast.makeText(getApplicationContext(),
                "Alaplista betöltése kész",
                Toast.LENGTH_SHORT)
                .show();
        return true;
    }

    if (id == R.id.lista_betoltese) {
        Toast.makeText(getApplicationContext(),
                "Mentett lista betöltése kész",
                Toast.LENGTH_SHORT)
                .show();
        return true;
    }

    if (id == R.id.lista_mentese) {
        Toast.makeText(getApplicationContext(),
                "Mentés kész",
                Toast.LENGTH_SHORT)
                .show();
        return true;
    }

    if (id == R.id.szerkeszto_mod) {
        szerkeszto_mod(!szerkesztomod);
        return true;
    }

    if (id == R.id.betumeret_noveles) {
        betumeret++;
        Toast.makeText(getApplicationContext(),
                "Betűméret: " + betumeret,
                Toast.LENGTH_SHORT)
                .show();
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
public void onOptionsMenuClosed (Menu menu) {
    super.onOptionsMenuClosed(menu);
    getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
                    View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}

解决方案

Use ActionBar.OnMenuVisibilityListener for receiving events when action bar menus are shown or hidden.

http://developer.android.com/reference/android/app/ActionBar.OnMenuVisibilityListener.html

这篇关于为什么OnOptionsMenuClosed不叫在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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