java - 不要关闭外部点击时的弹出窗口

标签 java android popupwindow

我有一个弹出窗口,我想以编程方式放大和关闭它,我不希望任何用户输入来关闭它。然而,当触摸弹出窗口外部的屏幕时,弹出窗口将被关闭,我知道以前已经问过这个问题,但我已经尝试了我发现的每一个变体,但我似乎无法完成这项工作...这是我的代码:

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/

相关文章:

java - 根据另一列值从总和中减去或添加值

java - 如何解析大型 JSON 文件以获取搜索栏建议

android - 大图像抛出 OutOfMemoryError

javascript - 您如何检测 Chrome 中是否阻止了指向另一个域的弹出窗口?

css - 选择并传递要在弹出窗口中显示的表格结果

java - Android Activity 内存管理

java.io.FileNotFoundException :/target/test. 日志

java - 是否可以在 libGDX 中仅通过平移和旋转创建一个简单的动画?

android - 如何调整 2 个工具栏以适应父级宽度

javascript - 用另一个 Javascript 调用停止 Javascript 函数?