Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

android - How To Control use of OverFlow Menu in ICS

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...