众所周知,Android碎片化严重的问题,对于底部导航的隐藏和显示出了N多个版本的问题。在开发的时候,又遇到了底部导航的问题,所以在此记录一下 处理方案。手头测试机数量有限,该方法对于小米,vivio,华为均适用。 直接看代码吧 。
/**
* @return 是否显示底部导航
*/
public static boolean isShowNav(Activity activity) {
boolean flag = false;
View content = activity.getWindow().getDecorView().findViewById(android.R.id.content);
if ( null != content) {
WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point point = new Point();
display.getRealSize(point);
if (!isLandscape()) {
int bottom = content.getBottom();// 页面的底部
if (bottom != point.y) {
flag = true;
}
} else {
int right = content.getRight();
if (right != point.y) {
flag = true;
}
}
}
}
return flag;
}
其中,isLandscape方法,是用来判断当前页面是横屏还是竖屏 。
/**
* Return whether screen is landscape.
*
* @return {@code true}: yes<br>{@code false}: no
*/
public static boolean isLandscape() {
return Utils.getApp().getResources().getConfiguration().orientation
== Configuration.ORIENTATION_LANDSCAPE;
}
需要的同学 可以测试一下 。