美文网首页
获取状态栏的高度

获取状态栏的高度

作者: cvmars | 来源:发表于2017-03-06 11:42 被阅读106次
 /**
     * 用于获取状态栏的高度。
     *
     * @return 返回状态栏高度的像素值。
       */
    private int getStatusBarHeight() {
        if (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();
            }
        }
        return statusBarHeight;
    }

相关文章

网友评论

      本文标题:获取状态栏的高度

      本文链接:https://www.haomeiwen.com/subject/dxnygttx.html