如何控制ICS使用溢出菜单菜单、ICS

2023-09-12 08:15:34 作者:暖不了的心

我想控制使用溢出菜单中的ICS。我也试过这种code在我onCreateView()与此参考link

 尝试{
            ViewConfiguration配置= ViewConfiguration.get(本);
            现场menuKeyField = ViewConfiguration.class.getDeclaredField(sHasPermanentMenuKey);
            如果(menu​​KeyField!= NULL){
                menuKeyField.setAccessible(真正的);
                menuKeyField.setBoolean(配置,FALSE);
            }
        }赶上(例外前){
            // 忽略
        }
 

请帮我在哪里,我错了,我怎么可以使用它。

解决方案   

我在哪里错了

您是错误的,其在应用中这个code。

  

我怎么可以使用它

如何使用控制面板菜单模式

您不应使用它。请允许溢出菜单正常行为。

首先,你的code可能无法在所有的设备和Android版本。

更重要的是,你正在做的是告诉你的用户,你认为你是更重要的不是他们。是什么

每个器件,根据操作系统版本和硬件,都有办法触发菜单:无论是 ... 启示操作栏中或设备的菜单按钮。用户希望的在其设备上的应用程序之间的一致性的。对于用户来说,其设备有一个MENU按钮,他们会期望使用菜单按钮的所有软件的弹出菜单(如有)。您正试图伤害这些用户,打破他们的菜单按钮。请不要这样做。请让您的应用程序的行为方式相同的应用程序对这些用户的设备上的休息,那里的菜单键可以调出溢出菜单。

更新

由于Android 4.4系统中,溢出...启示将出现在操作栏无论设备是否有一个菜单按钮,谷歌是把多一点pressure对设备制造商停止包括菜单按钮。 我已经在博客中多一点关于这个。

I want to control use of Overflow Menu in ICS. I have also tried this code in my onCreateView() with reference of this link

     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
        }

Kindly help me where I am wrong and how I can use it.

解决方案

where I am wrong

You are wrong for having this code in your app.

how I can use it

You should not use it. Please allow the overflow menu to behave normally.

First, your code may not work on all devices and Android versions.

More importantly, what you are doing is telling your users that you think that you are more important than they are.

Each device, based on OS version and hardware, has its means of triggering the menu: either the ... affordance in the action bar or the device's MENU button. Users want consistency between apps on their device. For users whose device has a MENU button, they will expect to use the MENU button in all apps to bring up menus where available. You are attempting to harm those users, by breaking their MENU button. Please do not do this. Please allow your app to behave the same way as the rest of the apps on those users' devices, where the MENU button brings up the overflow menu.

UPDATE

As of Android 4.4, the overflow ... affordance will appear in the action bar regardless of whether the device has a MENU button, and Google is putting a bit more pressure on device manufacturers to stop including a MENU button. I have blogged a bit more about this.