1

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.

Community
  • 1
  • 1
Rishabh Agrawal
  • 861
  • 2
  • 15
  • 25

1 Answers1

4

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for your suggestion.But i am working on Custome Locker.So if use can go home screen with overflow menu so what the use of custome locker. – Rishabh Agrawal Oct 13 '12 at 11:32
  • 1
    @Rishabh.CreatioSoft: The HOME button has nothing to do with the overflow menu. – CommonsWare Oct 13 '12 at 11:35
  • i got a sucess to control home button. – Rishabh Agrawal Oct 13 '12 at 12:15
  • 18
    you are not entirely correct. When creating a business app that is going to be used by a user about 8-12 hours a day it is bad to force user hitting the stupid menu button. Menu button sucks thats why they removed.Even old device owners rarely use it or guess that it might be there.. I had to search the web because it wasnt clear that there are more actions! You have to tell each user that "hey dude there actions that arent visible press menu button".Otherwise overflow is visible and tells you clearly that there is something there. – GorillaApe Dec 29 '12 at 23:30
  • 2
    @Parhs: "it is bad to force user hitting the stupid menu button" -- then do not use the options menu and action bar. Come up with your own UI, if you think you can do better. What idiots do, on the other hand, is create fragile apps by using reflection to mess with private data in the Android framework. That technique will not work across all versions of Android or on all devices (private implementation details can and is changed by device manufacturers). – CommonsWare Dec 29 '12 at 23:38
  • 3
    @CommonsWare this post explains the problem http://stackoverflow.com/a/13341458/294022 .Your answer is irrelevant, don't isolate a phrase from my sentence. You might be an expert and experienced but menu button + actionbar is totally unintuitive. The only reason to make actionbarsherlock behave like that is that official does it this way. – GorillaApe Dec 30 '12 at 00:00
  • 1
    @Parhs +1. The MENU button is completely unintuitive. When users see ActionBar with actions in the application the though "Maybe there are some hideen actions present? Why don't I press the MENU button?" is the last thing to come into their mind. There is a solution to emulate overflow button by using submenu http://stackoverflow.com/a/12777000/898457. It is ugly though, but does not involve using Reflection... – Alex Semeniuk Apr 15 '13 at 07:12
  • If Google want us to remove the Physical Menu (and a lot of guys agree it is more usable), and as long as it is only a software limitation, there is nothing to prevent us from adding an ActionBar menu in older devices. – Benoit Sep 09 '13 at 15:16
  • Even now twitter new app use this hack so its been benchmark :) – DjHacktorReborn Dec 18 '13 at 15:16