Android PopupWindow顯示時,隱藏底部導航欄
第一步:app全屏,常規設置
final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
getWindow().getDecorView().setSystemUiVisibility(flags);
第二步:創建PopupWindow
View contentView = LayoutInflater.from(host).inflate(R.layout.popup_window, null);
PopupWindow popupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
popupWindow.setOutsideTouchable(true);
popupWindow.setTouchable(true);
popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
popupWindow.setAnimationStyle(R.style.popuWindowAnimation);
popupWindow.showAtLocation(contentView, Gravity.TOP | Gravity.START, 0, 0);
說明:正常的這麼設置後,第一步中隱藏的底部導航欄,在第二步PopupWindow顯示時便不會再彈出。但其中重要的一點:
popupWindow.setFocusable(false)
默認setFocusable參數爲false,若參數設爲true,則在PopupWindow顯示時,底部導航欄會繼續彈出,第一步設置的全屏選項也會無效。