Android 获取状态栏高度

//获取系统状态栏高度
    public static int getStatusHeight(Context context) {
       //单位px
        int statusHeight = -1;
        try {
            Class clazz = Class.forName("com.android.internal.R$dimen");
            Object object = clazz.newInstance();
            int height = Integer.parseInt(clazz.getField("status_bar_height")
                    .get(object)
                    .toString());
            statusHeight = context.getResources().getDimensionPixelOffset(height);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return statusHeight;
    }

你可能感兴趣的:(Android 获取状态栏高度)