点击弹出窗口外将其关闭 [英] click outside of popup to dismiss it
本文介绍了点击弹出窗口外将其关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
<一href="http://stackoverflow.com/questions/8384067/how-to-dismiss-the-dialog-with-click-on-outside-of-the-dialog">How与点击对话外关闭对话框?
我如何可以点击弹出外解雇呢?
How can I click outside of a popup to dismiss it?
下面是我的code:
cell.setOnClickListener(new OnClickListener(){
/*This code is in a separate class so I needed to use ctx as context
*and the string "layout_inflater" because it was not recognizing
*LAYOUT_INFLATER_SERVICE*/
@Override
public void onClick(View arg0) {LayoutInflater layoutInflater =
(LayoutInflater)ctx.getSystemService("layout_inflater");
View popupView = layoutInflater.inflate(R.layout.popup_window, null);
final PopupWindow popupWindow = new PopupWindow(popupView,
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
popupWindow.showAtLocation(newParentLayout, Gravity.CENTER, 0, 0);
}
我也尝试添加了这一切,但没有结果。
I've also tried adding all of this but no results.
popupWindow.setTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setOutsideTouchable(true);
Drawable bg = ctx.getResources().getDrawable(R.drawable.popup_bg);
popupWindow.setBackgroundDrawable(bg);
我的想法。任何帮助?
I'm out of ideas. Any help?
编辑补充:主要布局是一个ViewPager / PagerAdapter如果这会影响什么
Edit to add: the main layout is a ViewPager/PagerAdapter if that would affect anything?
推荐答案
请设置setOutsideTouchable(真)随着背景。这工作对我罚款。我知道,设置背景绘制为null杀死OnTouchListener。
Please set setOutsideTouchable(true) along with the background. That worked fine for me. I know that setting the background drawable to null kills the OnTouchListener.
这篇关于点击弹出窗口外将其关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文