Android 获取导航栏高度

只能在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;
    }
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页