android怎么获取navigation bar显示或隐藏状态

在让navigation bar 显示货隐藏前,需要判断是否存在navigationbar。

public static boolean checkDeviceHasNavigationBar(Context activity) {

//通过判断设备是否有返回键、菜单键(不是虚拟键,是手机屏幕外的按键)来确定是否有navigation bar

boolean hasMenuKey = ViewConfiguration.get(activity)

.hasPermanentMenuKey();

boolean hasBackKey = KeyCharacterMap

.deviceHasKey(KeyEvent.KEYCODE_BACK);

if (!hasMenuKey && !hasBackKey) {

// 做任何自己需要做的,这个设备有一个导航栏

return true;

}

return false;

}

安卓4.1之后为全虚拟键操作,和actionbar对应,底部的虚拟键菜单称为Navigation Bar。

myview.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION),其中的myview 可以为Layout中任意的一个View对象(可以有findViewById得到)。