2012-10-09 73 views
1

在潛伏了很多所有類型的響應之後(感謝這個令人敬畏的網站),我問我的第一個問題。原諒我,如果我做錯了什麼!平板電腦上的SystemBar寬度

我想知道是否有辦法找到Android平板電腦系統的寬度。不是帶有虛擬按鈕(Back,Home,Menu ...)的部分,可點擊部分彈出所有通知消息。

而且如果有一個簡單的方法可以知道系統狀態欄是在頂部還是底部。從其他方面來看,getDecorView在任何情況下都不可靠。

謝謝!

回答

0

有可能會幫助您Height of statusbarSystem bar size on android tablets

在你不需要知道系統欄的位置很多情況下,並正確地畫出你的自定義組件幾個相關的問題(即不繫統欄覆蓋)所有你需要的是覆蓋fitSystemWindows如下圖所示:

(注意:當insets.top> 0時,你可以期望系統欄位於頂部,同樣當insets .bottom> 0

@Override 
protected boolean fitSystemWindows(Rect insets) { 

    ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) this 
      .getLayoutParams(); 

    int top = params.topMargin + insets.top; 
    int bottom = params.bottomMargin + insets.bottom; 
    int left = params.leftMargin + insets.left; 
    int right = params.rightMargin + insets.right; 
    /* Usually when insets.top > 0 means the systembar on the top and simiarly if insets.bottom > 0*/ 
    params.setMargins(left, top, right, bottom); 
    return true; 
} 
+0

謝謝,你的回答似乎對我的問題的第二部分作出了很好的迴應。我還沒有測試,但因爲它是3個月內的唯一回應,所以我現在驗證了它。 – user1732313

相關問題