[安卓开发]在有物理按键的设备上依旧在Action Bar中显示虚拟菜单键

只要在onCreate中加入如下代码即可,这里使用了反射:

 

         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
            }

 

posted @ 2013-04-03 12:22  子衿鄭風  阅读(234)  评论(0)    收藏  举报