/** * * @return */ public boolean phoneHasNav(){ boolean flag = false; if(Build.VERSION.SDK_INT < 14){ flag = false; }else { View content = getWindow().getDecorView().findViewById(android.R.id.content); if (content != null) { WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point point = new Point(); display.getRealSize(point); if (isScreenPortrait()) { int bottom = content.getBottom();// 页面的底部 if (bottom != point.y) { flag = true; } }else { int right = content.getRight(); if (right != point.y) { flag = true; } } } } return flag; } /** 获取屏幕是否是竖屏 * @return */ @SuppressLint("SwitchIntDef") public boolean isScreenPortrait(){ int or = getRequestedOrientation(); switch (or) { case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE :// 横屏 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: return false; case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT :// 竖屏 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: return true; default: return true; } }
这个是很精确地,写在Activity里面就可以使用了。原来是根据当前页面的底部和屏幕真实的高度做判断。很精确。我自己发明的。真的是,自己想的办法。卧槽。根据布局自己一点一点的试出来的。