Android 获取底部导航栏高度
目前存在的都不怎么完美,特别涉及到三星、华为等手机,经过测试目前华为、三星、小米手机基本满足,而且不需要判断手机型号。
直接上代码:
public static int getNavigationBarHeight(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Display display = activity.getWindowManager().getDefaultDisplay();
Point size = new Point();
Point realSize = new Point();
display.getSize(size);
display.getRealSize(realSize);
Resources resources = activity.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
int height = resources.getDimensionPixelSize(resourceId);
//超出系统默认的导航栏高度以上,则认为存在虚拟导航
if ((realSize.y - size.y) > (height - 10)) {
return height;
}
return 0;
} else {
boolean menu = ViewConfiguration.get(activity).hasPermane