@Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
getWindow().findViewById(Window.ID_ANDROID_CONTENT);
Display display = getWindowManager().getDefaultDisplay();
//屏幕高度
int height = display.getHeight();
Rect frame = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
// 状态栏高度
int statusBarHeight = frame.top;
}
本文介绍了如何在Android应用中通过onWindowFocusChanged方法获取屏幕的高度及状态栏的高度。此方法确保了在视图完全加载并聚焦后进行测量,从而避免了在onCreate()方法中可能遇到的问题。
1010

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



