@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
Rect frame = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
// 获取标题栏高度
Window window = getWindow();
int contentViewTop = getWindow()
.findViewById(Window.ID_ANDROID_CONTENT).getTop();
// statusBarHeight是上面所求的状态栏的高度
titleBarHeight = contentViewTop - statusBarHeight;
Log.i("test", "statusBarHeight=" + statusBarHeight + " contentViewTop="
+ contentViewTop + " titleBarHeight=" + titleBarHeight);
}
本文介绍了一种在Android应用中通过onWindowFocusChanged方法获取状态栏和标题栏高度的方法。通过计算窗口可见显示区域的顶部位置,可以确定状态栏高度,并进一步计算出标题栏的高度。
843

被折叠的 条评论
为什么被折叠?



