没有出现在Android 4.4系统的Andr​​oid菜单选项 [英] Android Menu option not appearing in Android 4.4

查看:124
本文介绍了没有出现在Android 4.4系统的Andr​​oid菜单选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序,我已经测试工作在Android 4.0的一个选项菜单。 在code为如下图所示:

I have a options menu in my application which I have tested to work on Android 4.0. The code is as shown below:

@Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.layout.menu, menu);
        return true;
    }

    /**
     * Event Handling for Individual menu item selected
     * Identify single menu item by it's id
     * */
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {

        switch (item.getItemId())
        {

        case R.id.menu_share:

             //code to do something when chosen etc


            return true;

        default:
            return super.onOptionsItemSelected(item);
        }
    } 

现在,如果我运行在Android 4.4在同一code(我测试了摩托G),选项菜单没有出现。

Now if I run the same code on Android 4.4 (I tested on Moto G), the options menu is not appearing.

知不知道我必须做的,因为有关联的设备?

Any idea what I must do since there is no Android menu button on the device?

推荐答案

您的活动类里面将这个如果要强制应用程序以显示操作溢出:

Put this inside your activity class if you want to Force to the Application to show the Action Overflow:

    try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class
                .getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Ignore
    }

这篇关于没有出现在Android 4.4系统的Andr​​oid菜单选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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