2017-10-18,在给领导展示自己新成果的时候又被打脸了,TMD我测试用的是小米的手机,结果领导的是华为的手机,展示底部PopWindow时最下面那一段被截掉了,废话不多说了,直接上代码:
/**
* 获取虚拟按键的高度
* @param context
* @return
*/
public static Point getNavigationBarSize(Context context) {
Point appUsableSize = getAppUsableScreenSize(context);
Point realScreenSize = getRealScreenSize(context);
// navigation bar on the right
if (appUsableSize.x < realScreenSize.x) {
return new Point(realScreenSize.x - appUsableSize.x, appUsableSize.y);
}
// navigation bar at the bottom
if (appUsableSize.y < realScreenSize.y) {
return new Point(appUsableSize.x, realScreenSize.y - appUsableSize.y);
}
// navigation bar is not present
return new Point();
}
public static Point getAppUsableScreenSize(Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
Point size =new Point();
display.getSize(size);
return size;
}
public static Point getRealScreenSize(Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
Point size =new Point();
if(Build.VERSION.SDK_INT>=17) {
display.getRealSize(size);
}else if(Build.VERSION.SDK_INT>=14) {
try{
size.x= (Integer) Display.class.getMethod("getRawWidth").invoke(display);
size.y= (Integer) Display.class.getMethod("getRawHeight").invoke(display);
}catch(IllegalAccessException e) {}catch(InvocationTargetException e) {}catch(NoSuchMethodException e) {}
}
return size;
}
网友评论