我有一个带有PopupWindow的片段。我用以下代码启动Popup:当外部点击时关闭PopupWindow在
private PopupWindow createPopup;
private void initiateWindow(){
try {
LayoutInflater inflater = (LayoutInflater) getActivity()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.window_popup,
(ViewGroup) v.findViewById(R.id.popup_element));
DisplayMetrics displaymetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
createPopup = new PopupWindow(layout, width/2 + width/4, height/3, true);
createPopup.showAtLocation(layout, Gravity.CENTER, 0, 0);
} catch (Exception e) {
e.printStackTrace();
}
}
它运行得很好。我想在外部点击时关闭窗口。这是一件很平常的事情,所以关于互联网上的话题有很多教程和问题。问题是 - 他们都无法工作。
我试过使用createPopup.setBackgroundDrawable(newColorDrawable(Color.TRANSPARENT)); createPopup.setOutsideTouchable(true); createPopup.setFocusable(true);
和类似answers。
我还检查了是否可以使用此createPopup.setBackgroundDrawable(newColorDrawable(Color.BLACK));
填充纯色弹出框后面的所有内容,以验证我是否有错误的核心代码,但它也没有帮助 - 与弹出布局无关的所有内容都保持可见状态。
它会自动关闭时点击它之外。不是没有关闭? –
不,它不。 –
好的没问题什么弹出窗口包含什么视图textviews? –