setOutsideTouchable
setOutsideTouchable(true),点击非PopupWindow视图区域,直接隐藏PopupWindow。调用setOutsideTouchable(true)会使得点击非PopupWindow视图区域,PopupWindow能够接收到ACTION_OUTSIDE事件,接收到这个事件后执行dismiss。但是在5.0以下需要调用setBackground给PopupWindow设置一个非空的背景才会起作用。
小于5.0分析
5.0以下的PopupWindow,当mBackground为非null时,才会创建PopupViewContainer来封装contentView,而ACTION_OUTSIDE的处理正是由其来处理。点击查看4.4源代码
private void preparePopup(WindowManager.LayoutParams p) {
......
if (mBackground != null) {
......
PopupViewContainer popupViewContainer = new PopupViewContainer(mContext);
......
mPopupView = popupViewContainer;
} else {
mPopupView = mContentView;
}
......
}
priv