只能在activity中使用,或者自己更改下传入一个 不要覆盖导航栏的window自己更改下代码。
public int getNavigationBarHeight(Context context) {
if (!(context instanceof Activity)) {
return 0;
}
int height;
Display display = ((Activity) context).getWindow().getWindowManager().getDefaultDisplay();
Point point = new Point();
display.getRealSize(point);
View decorView = ((Activity) context).getWindow().getDecorView();
Configuration conf = context.getResources().getConfiguration();
if (Configuration.ORIENTATION_LANDSCAPE == conf.orientation) {
View contentView = decorView.findViewById(android.R.id.content);
height = Math.abs(point.x - contentView.getWidth());
} else {
Rect rect = new Rect();
decorView.getWindowVisibleDisplayFrame(rect);
height = Math.abs(rect.bottom - point.y);
}
return height;
}