Android 会有虚拟导航栏,那么如何让某个 Activity 显示导航栏上的虚拟menu键呢,可以参考下面的方法。
/**
* 显示导航栏的虚拟menu键
*/
private void showNagtiveMenu() {
int menuFlag = 0;
try {
menuFlag = WindowManager.LayoutParams.class.getField("FLAG_NEEDS_MENU_KEY").getInt(null);
Window window = getWindow();
window.addFlags(menuFlag);
return;
} catch (NoSuchFieldException e) {
Log.e(LOGTAG, "NoSuchFieldException : " + e.getLocalizedMessage().toString() );
} catch (IllegalAccessException e) {
Log.e(LOGTAG, "IllegalAccessException : " + e.getLocalizedMessage().toString() );
} catch (Exception e) {
Log.e(LOGTAG, "Exception : " + e.getLocalizedMessage().toString() );
}
try {
menuFlag = WindowManager.LayoutParams.class.getField("NEEDS_MENU_SET_TRUE").getInt(null);
Method m = Window.class.getDeclaredMethod("setNeedsMenuKey", int.class);
m.setAccessible(true);
m.invoke( getWindow(), new Object[]{menuFlag} );
} catch (Exception e) {
Log.e(LOGTAG, "Exception : " + e.getLocalizedMessage().toString() );
}
}