本文介绍了openOptionsMenu功能不工作在ICS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯使用操作栏compability库。我试着从与openOptionsMenu()功能的按钮打开选项菜单,但它什么都不做。

菜单显示和往常一样,当pressing我的手机上的菜单键。什么是错在这里?

 公共类ReadActivity扩展ActionBarActivity {

    ...

    @覆盖
    公共布尔onCreateOptionsMenu(功能菜单){
        布尔值;
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.read,菜单);
        值= super.onCreateOptionsMenu(菜单);

        如果(Helper.SupportsNewApi()){
            getActionBar()隐藏()。
        } 其他 {
            ((查看)((的LinearLayout)findViewById(R.id.actionbar_compat))
                    。.getParent())setVisibility(View.GONE);
        }

        返回值;
    }

    @覆盖
    公共布尔onOptionsItemSelected(菜单项项){
        开关(item.getItemId()){
        案例android.R.id.home:
            完();
            打破;
        案例R.id.menu_search:
            // Toast.makeText(这一点,螺纹搜索,Toast.LENGTH_SHORT).show();
            打破;
        案例R.id.menu_bookmark:
            // selectText();
            // setFullScreen(假);
            打破;
        案例R.id.menu_day_night_mode:
            打破;
        案例R.id.menu_settings:
            打破;
        案例R.id.menu_zoom_in:
            showOverlay(假);
            打破;
        案例R.id.menu_zoom_out:
            showOverlay(假);
            打破;
        案例R.id.menu_table_of_contents:
            意图tocIntent =新的意图(这一点,TocActivity.class);
            INT GET_SECTION_REFERENCE = 1;
            startActivityForResult(tocIntent,GET_SECTION_REFERENCE);
            打破;
        案例R.id.menu_overflow:
            Toast.makeText(这一点,螺纹溢出,Toast.LENGTH_SHORT).show();

            // closeOptionsMenu();
            openOptionsMenu(); //尝试下面的藏汉,没有结果
            //getWindow().openPanel(Window.FEATURE_OPTIONS_PANEL,NULL);
            打破;
        }
        返回super.onOptionsItemSelected(项目);
    }


    @Override //关闭音量按钮
    公共布尔的onkeydown(INT键code,KeyEvent的事件){
        如果(menu​​Shown&安培;!及(键code == 25 ||键code == 24)){
            返回true;
        }
        返回super.onKeyDown(键code,事件);
    }

    @覆盖
    公共布尔的onkeyup(INT键code,KeyEvent的事件){
        Log.d(标签,关键code是=+键code);
        如果(键code == 82){
            如果(!menuShown){
                // openOptionsMenu();
                showOverlay(真正的);
            } 其他 {
                showOverlay(假);
            }


                    //不希望它打开时,pressing菜单
            返回true;
        }否则,如果(键code == 4安培;&安培; menuShown){
            showOverlay(假);
            返回true;
        }否则,如果(键code == 25安培;&安培;!menuShown){
            prevPage();
            返回true;
        }否则,如果(键code == 24安培;&安培;!menuShown){
            下一页();
            返回true;
        }

        返回super.onKeyUp(键code,事件);
    }

}
 

解决方案

我不知道怎么关这个,但是的论坛后,我发现好像是answerring同样的问题你。

我希望这篇文章是有关足以解决你的问题。

祝你好运!

Im using action bar compability library. Im trying to open the options menu from a button with openOptionsMenu() function but it does nothing.

Menu shows as usual when pressing the menu key on my phone. What is wrong here?

public class ReadActivity extends ActionBarActivity {

    ...

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        boolean value;
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.read, menu);
        value = super.onCreateOptionsMenu(menu);

        if (Helper.SupportsNewApi()) {
            getActionBar().hide();
        } else {
            ((View) ((LinearLayout) findViewById(R.id.actionbar_compat))
                    .getParent()).setVisibility(View.GONE);
        }

        return value;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            break;
        case R.id.menu_search:
            // Toast.makeText(this, "Tapped search", Toast.LENGTH_SHORT).show();
            break;
        case R.id.menu_bookmark:
            // selectText();
            // setFullScreen(false);
            break;
        case R.id.menu_day_night_mode:
            break;
        case R.id.menu_settings:
            break;
        case R.id.menu_zoom_in:
            showOverlay(false);
            break;
        case R.id.menu_zoom_out:
            showOverlay(false);
            break;
        case R.id.menu_table_of_contents:
            Intent tocIntent = new Intent(this, TocActivity.class);
            int GET_SECTION_REFERENCE = 1;
            startActivityForResult(tocIntent, GET_SECTION_REFERENCE);
            break;
        case R.id.menu_overflow:
            Toast.makeText(this, "Tapped overflow", Toast.LENGTH_SHORT).show();

            //closeOptionsMenu();
            openOptionsMenu(); //tried the below aswell, no results
            //getWindow().openPanel(Window.FEATURE_OPTIONS_PANEL, null);
            break;
        }
        return super.onOptionsItemSelected(item);
    }


    @Override //disable volume buttons
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (!menuShown && (keyCode == 25 || keyCode == 24)) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        Log.d(tag, "Keycode is = "+keyCode);
        if (keyCode == 82) {
            if (!menuShown) {
                //openOptionsMenu();
                showOverlay(true);
            } else {
                showOverlay(false);
            }


                    //don't want it to open when pressing menu
            return true;
        } else if (keyCode == 4 && menuShown) {
            showOverlay(false);
            return true;
        } else if (keyCode == 25 && !menuShown) {
            prevPage();
            return true;
        } else if (keyCode == 24 && !menuShown) {
            nextPage();
            return true;
        }

        return super.onKeyUp(keyCode, event);
    }

}
解决方案

I'm not sure how relevant this is, but this forum post I found seems to be answerring the same question you have.

I hope this post is relevant enough to solve your problem.

Good luck!

这篇关于openOptionsMenu功能不工作在ICS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 05:15