Android工具类

1、获取状态栏高度

private int getStatusBarHeight() {
        Rect rectangle = new Rect();
        Window window = getWindow();
        window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
        int statusBarHeight = rectangle.top;

        if (statusBarHeight == 0) {
            int resourceId = getResources().getIdentifier(
                    "status_bar_height", "dimen", "android");
            if (resourceId > 0) {
                statusBarHeight = getResources()
                        .getDimensionPixelSize(resourceId);
            }
        }
        return statusBarHeight;
    }


你可能感兴趣的:(Android,小技巧,android)