最近項目遇到了一個問題,關于Navigation Bar遮擋PopupWindow的問題蜕依,問題不難,粗略做一點總結友瘤。
現(xiàn)象描述
- 問題應該出現(xiàn)在5.0 Lollipop版本及以上
- 遮擋的現(xiàn)象如下圖,Navigation Bar位于了PopupWindow的上層辫秧,明顯是一種問題被丧。
navigation_issue.png
實現(xiàn)代碼
private void showPopupWindow() {
if (mPopupWindow == null) {
View contentView = LayoutInflater.from(this).inflate(R.layout.popup_window_content, null);
mPopupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT,500, true);
mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
}
mPopupWindow.showAtLocation(findViewById(R.id.contentContainer), Gravity.BOTTOM, 0,0);
}
其實和具體的實現(xiàn)代碼沒有關系甥桂,重點是修改主題style。
修改style
修改v21/styles.xml(如沒有笛求,可以創(chuàng)建),將android:windowDrawsSystemBarBackgrounds修改為false糕簿。
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
修改好的效果
navigation_bar_good.png
更佳的方法
popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
注意:這個方法不會影響到狀態(tài)欄的顏色改變懂诗,而第一種方法會苗膝。