如何点击PopupWindow点击外面?

时间:2015-07-13 11:13:26

标签: android android-popupwindow

我在项目中使用$http({ method: "delete", url: envConfig.restUrl + "customers/" + customer.id }).success(function(data, status, headers, config){ $scope.customers.splice($scope.customers.indexOf(customer), 1); }); 。 触摸显示时我无法忽略它。我试过了:

PopupWindow

但它没有用。我尝试@Override public void onResume() { super.onResume(); new Handler().postDelayed(new Runnable() { @Override public void run() { View popup = LayoutInflater.from(getActivity()).inflate(R.layout.popup, null, false); final PopupWindow popupWindow = new PopupWindow(popup, (int) DpiToPixel.calculateDpToPixel(150, getActivity()), (int) DpiToPixel.calculateDpToPixel(150, getActivity()), true); popupWindow.showAtLocation(rootView, Gravity.CENTER, 0, 0); popup.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { popupWindow.dismiss(); } }); popupWindow.setOutsideTouchable(true); popupWindow.setTouchable(true); popupWindow.setBackgroundDrawable(new BitmapDrawable()); popupWindow.setTouchInterceptor(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { Toast.makeText(getActivity(),"Click!",Toast.LENGTH_LONG).show(); popupWindow.dismiss(); return true; } }); } }, 100L); } 我在popupWindow.setFocusable(true);上尝试setBackgroundDrawable都无法正常工作。我该如何解雇这个弹出窗口?????????????

2 个答案:

答案 0 :(得分:0)

设置BackgroundDrawable,然后将setOutsideTouchable参数设置为true。

  

setOutsideTouchable:指示弹出窗口是否为   通知其窗外的触摸事件。

popupWindow.setBackgroundDrawable(new ColorDrawable());
myPopupWindow.setOutsideTouchable(true);

或试试这个:

myPopupWindow.setFocusable(true);

答案 1 :(得分:0)

将此语句移至run()方法的末尾:

popupWindow.showAtLocation(rootView, Gravity.CENTER, 0, 0);

换句话说,在之后完成所有调用后,不要显示弹出窗口。