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);
}