Android中获取状态栏的高度

代码

/**
 * @brief GetStatusBarHeight 获取状态栏的高度
 *
 * @return 
 */
public static int GetStatusBarHeight() {
    int statusBarHeight = 0;
    
    if (mActivity != null) {
        Rect rectgle = new Rect();
        Window window = mActivity.getWindow();
        window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
        statusBarHeight= rectgle.top;
    }

    return statusBarHeight;
}