Android 平台最近遇到一个关于 ViewConfiguration 的使用,并不是怎么理解,稍微百度了一下看到了下面这个,才明白,原来代码中这个是判断菜单是否显示的
菜单显示是根据public boolean hasPermanentMenuKey ()这个方法来判断的。这个方法是获取sHasPermanentMenuKey的boolean值。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if (menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, true);
}
} catch (Exception ex) {
// ignore
}}