我有一个弹出窗口,我想以编程方式放大和关闭它,我不希望任何用户输入来关闭它。然而,当触摸弹出窗口外部的屏幕时,弹出窗口将被关闭,我知道以前已经问过这个问题,但我已经尝试了我发现的每一个变体,但我似乎无法完成这项工作...这是我的代码:
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
提前致谢! :)
最佳答案
已修复!新代码:
boolean focusable = false;
popupWindow.setBackgroundDrawable(null);
以下内容已删除:
popupWindow.setTouchable(true);
popupWindow.setOutsideTouchable(true);
popupWindow.setTouchInterceptor((View view, MotionEvent motionEvent) -> {return false;});
关于java - 不要关闭外部点击时的弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62030543/