有可能會幫助您Height of statusbar和 System 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;
}
謝謝,你的回答似乎對我的問題的第二部分作出了很好的迴應。我還沒有測試,但因爲它是3個月內的唯一回應,所以我現在驗證了它。 – user1732313