判断是否手机是否有导航栏
private boolean hasNavigationBar() { Display display = getWindowManager().getDefaultDisplay(); DisplayMetrics displayMetrics = new DisplayMetrics(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { // 获取设备的硬件屏幕高度 display.getRealMetrics(displayMetrics); int realHeightPixels = displayMetrics.heightPixels; int realWidthPixels = displayMetrics.widthPixels; // 内容区域的屏幕高度 displayMetrics = new DisplayMetrics(); display.getMetrics(displayMetrics); int heightPixels = displayMetrics.heightPixels; int widthPixels = displayMetrics.widthPixels; int dHight = realHeightPixels - heightPixels; int dWidth = realWidthPixels - widthPixels; return dHight > 0 || dWidth > 0; } return false; }
最后,关注【码上加油站】微信公众号后,有疑惑有问题想加油的小伙伴可以码上加入社群,让我们一起码上加油吧!!!