你的位置:首页 > 操作系统

[操作系统]Android获取状态栏高度


    private int getStatusBarHeight() {

        int statusBarHeight = 0;

            try {

                Class<?> c = Class.forName("com.android.internal.R$dimen");

                Object o = c.newInstance();

                Field field = c.getField("status_bar_height");

                int x = (Integer) field.get(o);

                statusBarHeight = getResources().getDimensionPixelSize(x);

            } catch (Exception e) {

                e.printStackTrace();

                Rect frame = new Rect();

                getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);

                statusBarHeight = frame.top;

            }

            return statusBarHeight;

    }