gpt4 book ai didi

java - 在 onCreate() 中获取 statusBar 高度

转载 作者:行者123 更新时间:2023-11-29 05:52:42 25 4
gpt4 key购买 nike

我试图在 onCreate 中获取 statusBar 高度,但是我在这里找到的方法需要一些已经绘制的 View 来获取它的大小,然后计算 statusBar 高度。

因为我在 onCreate 上,所以我还没有绘制任何东西来确定它的大小

有人可以帮我吗?

最佳答案

root = (ViewGroup)findViewById(R.id.root);
root.post(new Runnable() {
public void run(){
Rect rect = new Rect();
Window win = getWindow();
win.getDecorView().getWindowVisibleDisplayFrame(rect);
int statusHeight = rect.top;
int contentViewTop = win.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int titleHeight = contentViewTop - statusHeight;
Log.e("dimen", "title = " + titleHeight + " status bar = " + statusHeight);
}
});

关于java - 在 onCreate() 中获取 statusBar 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13321096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com