Android如何獲取系統高度 標題欄和狀態列高度

2021-07-10 04:11:15 字數 504 閱讀 2762

getwindow().getdecorview().getwindowvisibledisplayframe(rect);///取得整個檢視部分,注意,如果你要設定標題樣式,這個必須出現在標題樣式之後,否則會出錯

int top = rect.top;狀態列的高度,所以rect.height,rect.width分別是系統的高度的寬度

view v = getwindow().findviewbyid(window.id_android_content);///獲得根檢視

int top2 = v.gettop();///狀態列標題欄的總高度,所以標題欄的高度為top2-top

int width = v.getwidth();///檢視的寬度,這個寬度好像總是最大的那個

int height = v.getheight();檢視的高度,不包括狀態列和標題欄

display display = getwindowmanager().getdefaultdisplay() ;只想取得螢幕大小可以用

Android獲取StatusBar高度的原理

獲取statusbar工具類 常見的獲取狀態列高度的工具類如下 public static int getstatusbarheightcompat context context if result 0 return result 這裡的status bar height是 來的呢?statusb...

Android獲取螢幕寬度高度

方法一 windowmanager wm windowmanager this getsystemservice context.window service int width wm.getdefaultdisplay getwidth int height wm.getdefaultdispla...

Android高度相關的獲取

新增鏈結描述 螢幕真實高度 return targetapi build.version codes.jelly bean mr1 public int getrealmetrics 螢幕高度 如果有虛擬鍵盤 獲取到的就不是螢幕的真實高度 return public int getmetrics d...