Android 获取 屏幕状态栏高度和标题栏高度 避免出现0的情况
生活随笔
收集整理的這篇文章主要介紹了
Android 获取 屏幕状态栏高度和标题栏高度 避免出现0的情况
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
@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); }
轉載于:https://my.oschina.net/sfshine/blog/493847
總結
以上是生活随笔為你收集整理的Android 获取 屏幕状态栏高度和标题栏高度 避免出现0的情况的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android 角色时间戳
- 下一篇: GIT子模块的使用