获取status bar的高度

    private int getStatusBarheight() {
        try {
            Class clazz = Class.forName("com.android.internal.R$dimen");
            Object obj = clazz.newInstance();
            Field field = clazz.getField("status_bar_height");
            int resId = Integer.parseInt(field.get(obj).toString());
            int height = getResources().getDimensionPixelSize(resId);
            return height;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
        return 0;
    }

你可能感兴趣的:(Android)