[英]Popup doesn't hide when touch outside
当我在一个空的地方点击时,我需要关闭弹出窗口,但是在滚动时,我需要显示一个弹出窗口。 现在,滚动时隐藏了我的弹出窗口,请帮助我解决此问题。 这是我的代码:
private void showPopup(View view, String text) {
if (infoPopup == null) {
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
View popupView = layoutInflater.inflate(R.layout.popup, null);
TextView tvPopupText = popupView.findViewById(R.id.tv_popup);
tvPopupText.setText(text);
FrameLayout flBackground = popupView.findViewById(R.id.fl_bg);
flBackground.setBackground(new BubbleDrawable(getContext(), R.color.azure, 16, 16, 8));
infoPopup = new PopupWindow(popupView,
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
infoPopup.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
// infoPopup.setOutsideTouchable(true);
infoPopup.showAsDropDown(view);
infoPopup.setTouchInterceptor(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
dismissInfoPopup();
return true;
}
return false;
}
});
} else {
dismissInfoPopup();
}
}
private void dismissInfoPopup() {
if (infoPopup != null) {
infoPopup.dismiss();
}
infoPopup = null;
}
现在,当我滚动时会显示弹出窗口,但是当我在外部点击时弹出窗口不会隐藏。
弹出显示后添加以下行
infoPopup.setBackgroundDrawable(new BitmapDrawable());
infoPopup.setOutsideTouchable(true);
编辑
infoPopup.setFocusable(true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.