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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/androidwubo/article/details/81507374

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、完成

阅读更多

没有更多推荐了,返回首页