我无法获得自定义弹出窗口的外部触摸,我的弹出窗口应该是可聚焦的,因为它有一些需要软键盘的EditText。
这是我的代码:
mPopupWindowAddnewItem= new PopupWindow(mPopupView,
mView_add_Popup.getWidth(), LayoutParams.WRAP_CONTENT, true);
mPopupWindowAddnewItem.setContentView(mPopupView);
mPopupWindowAddnewItem.setFocusable(true);
mPopupWindowAddnewItem.setOutsideTouchable(true);
mPopupWindowAddnewItem.setBackgroundDrawable(new BitmapDrawable());
mPopupWindowAddnewItem.setTouchInterceptor(new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motion) {
// TODO Auto-generated method stub
if(motion.getAction()== MotionEvent.ACTION_OUTSIDE){
showExistDialog();
return true;
}
else
if(motion.getAction() ==MotionEvent.ACTION_DOWN){
Rect mPopupRect=new Rect();
mPopupWindowAddnewItem.getContentView().getDrawingRect(mPopupRect);
if(mPopupRect.contains((int) motion.getRawX(),
(int) motion.getRawY())){
return false;
}else{
showExistDialog();
return true;
}
}
return false;
}
});
mPopupWindowAddnewItem.showAsDropDown(mView_add_Popup);
在我的代码中,如果条件和弹出视图的矩形检查总是返回false,它总是进入其他内部,即使我在PopWindow内部触摸。 对此有何解决方案?
答案 0 :(得分:1)
我已通过此代码解决了我的问题:
else if(motion.getAction() ==MotionEvent.ACTION_DOWN){
Rect mPopupRect=new Rect();
mPopupWindowAddnewItem.getContentView().getDrawingRect(mPopupRect);
if(mPopupRect.contains((int)motion.getX(),
(int) motion.getY())){
return false;
}else{
showExistDialog();
return true;
}
}