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;
    }
发布了16 篇原创文章 · 获赞 5 · 访问量 6561

猜你喜欢

转载自blog.csdn.net/ggy_yao/article/details/84842466