Android(安卓)获取NavigationBar高度
16lz
2022-04-03
使用方法如下:
Point point = getNavigationBarSize(this);bottomHeight = point.y; if (bottomHeight > 0) { //有NavigationBar }
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(); } @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) 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; }
更多相关文章
- android SpannableString使用详解
- android studio 使用getActionBar返回NULL
- Android调用第三方App
- Android(安卓)使用广播(BroadcastReceiver)传递数据
- Android中ContextMenu的使用
- Android之使用Activity与Fragment通信
- 箭头函数的基础使用
- NPM 和webpack 的基础使用
- Python list sort方法的具体使用