Android實現popupwindow彈出後螢幕背景變成半透明效果
阿新 • • 發佈:2019-02-11
/**
* 設定新增螢幕的背景透明度
*
* @param bgAlpha
*/
public void backgroundAlpha(float bgAlpha) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = bgAlpha; //0.0-1.0
getWindow().setAttributes(lp);
}
PopupWindow popWin = new PopupWindow(view1,LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); //在PopupWindow裡面就加上下面程式碼,讓鍵盤彈出時,不會擋住pop視窗。 popWin.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED); popWin.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); //點選空白處時,隱藏掉pop視窗 popWin.setFocusable(true); popWin.setBackgroundDrawable(new BitmapDrawable()); backgroundAlpha(1f); popWin.showAtLocation(liner, Gravity.BOTTOM, 0, 0);