获取高度
获取StatusBar高度¶
本文记录获取StatusBar高度的方法。
在activity中获取DecorView
,然后拿到可见区域WindowVisibleDisplayFrame。
private void getStatusBarHeight() {
Rect rectangle = new Rect();
Window window = getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
// rectangle.top 就是高度
Log.d(TAG, "getStatusBarHeight: " + rectangle.top);
}