欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

android popupwindow点击外侧不消失,且不影响外部交互

程序员文章站 2022-05-31 15:38:51
...

1、创建popupwindow

View contentView = LayoutInflater.from(CheckMapActivity.this).inflate(R.layout.popuplayout, null);
        mPopupWindow = new PopupWindow(contentView,
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);

        // 设置这两个属性
        mPopupWindow.setOutsideTouchable(false);
        mPopupWindow.setFocusable(false);


        mPopupWindow.setContentView(contentView);

        //显示PopupWindow
        View rootview = LayoutInflater.from(CheckMapActivity.this).inflate(R.layout.activity_map2, null);
        mPopupWindow.showAtLocation(rootview, Gravity.BOTTOM, 0, 0);

2、重写dispatchTouchEvent

@Override
    public boolean dispatchTouchEvent(MotionEvent event){
        return super.dispatchTouchEvent(event);
    }

3、完成

相关标签: popupwindow