/**
* 获取是否有虚拟按键
* 通过判断是否有物理返回键反向判断是否有虚拟按键
* @param context
* @return
*/
public static boolean checkDeviceHasNavigationBar(Context context) {
boolean hasMenuKey = ViewConfiguration.get(context)
.hasPermanentMenuKey();
boolean hasBackKey = KeyCharacterMap
.deviceHasKey(KeyEvent.KEYCODE_BACK);
if (!hasMenuKey & !hasBackKey) {
// 做任何你需要做的,这个设备有一个导航栏
return true;
}
return false;
}
//获取虚拟按键的高度
public static int getNavigationBarHeight(Context context) {
int result = 0;
if (checkDeviceHasNavigationBar(context)) {
Resources res = context.getResources();
int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
result = res.getDimensionPixelSize(resourceId);
}
}
return result;
}