android - 触摸外部时弹出窗口不隐藏
问题描述
在空白处点击时我需要关闭我的弹出窗口,但是当滚动时我需要显示一个弹出窗口。现在当我滚动时我的弹出窗口被隐藏了,请帮我解决这个问题。这是我的代码:
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);
推荐阅读
- oracle10g - oracle 回收站中显示“未找到数据”
- android - 如何解决 dlopen failed: library "../../lib/libtbb.so" not found 错误?
- ios - 如何更改具有可变图像名称的按钮的图像?
- css - 不剪辑内容的剪辑路径
- tensorflow - 如果样本大小不能被 Keras 模型中的 batch_size 整除怎么办
- php - 使用 PHP mySQL 显示来自两个 sql 表的数据
- c# - 找不到位图
- c++ - 静态全局变量初始化顺序
- python - 在 pytest 中创建不同的环境设置
- android - 如何自定义 SwipeToReferesh 布局顶部 ProgressBar 或 Loader?