不要关闭外部点击弹出窗口

时间:2020-05-26 20:07:22

标签: 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

提前谢谢! :)

1 个答案:

答案 0 :(得分:0)

已修复!新代码:

 boolean focusable = false;
 popupWindow.setBackgroundDrawable(null);

以下内容已删除:

popupWindow.setTouchable(true);
popupWindow.setOutsideTouchable(true);
popupWindow.setTouchInterceptor((View view, MotionEvent motionEvent) -> {return false;});