我有一个弹出窗口,希望以编程方式进行充气和关闭,我不希望任何用户输入都将其关闭。但是,当触摸弹出式屏幕之外的屏幕时,弹出式窗口被关闭了,我知道这个问题已经被问过了,但是我已经尝试了发现的每个变体,但似乎无法使它工作……这是我的代码:
LayoutInflater inflater = (LayoutInflater)
mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = inflater.inflate(R.layout.custom_loading, null);
int width = LinearLayout.LayoutParams.WRAP_CONTENT;
int height = LinearLayout.LayoutParams.WRAP_CONTENT;
boolean focusable = false;
popupWindow = new PopupWindow(popupView, width, height, focusable);
popupWindow.setElevation(20);
popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(mContext, R.drawable.transparent_back));
popupWindow.setTouchable(true);
popupWindow.setOutsideTouchable(true);
popupWindow.setTouchInterceptor((View view, MotionEvent motionEvent) -> {return false;});
popupWindow.showAtLocation(v, Gravity.CENTER, 0, 0);// v is a view passed as a parameter to the function
谢谢! :)
尝试更改此内容
popupWindow.setOutsideTouchable(false);