I would like to use a PopupWindow with following behaviours/features:
I've found bunch of posts regarding PopupWindow but none of them asked question how to deal with such situation..
I think I tried every possible combination of setOutsideTouchable(), setFocusable(),setTouchable() but I'm stuck. Popup deals with clicks on it properly, but it's dismissed always when touching outside.
My current code is :
View.OnTouchListener customPopUpTouchListenr = new View.OnTouchListener(){
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
Log.d("POPUP", "Touch false");
return false;
}
};
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout layout= (LinearLayout)inflater.inflate(R.layout.insert_point_dialog, null);
PopupWindow pw = new PopupWindow(layout,400,200,true);
pw.setOutsideTouchable(true);
pw.setTouchable(true);
pw.setBackgroundDrawable(new BitmapDrawable());
pw.setTouchInterceptor(customPopUpTouchListenr);
pw.showAtLocation(frameLayout, Gravity.BOTTOM, 0, 0);
My general goal is to create a floating window which behaves like a 'tools palette' in software like gimp: has some controls inside, stays on top until closed by 'X' button, and allowing to interact with controls outside-under it.. Maybe there's some better way to do this, not a PopupWindow? But I still haven't found more suitable control.
Nothing suggested here, or elsewhere seemed to work for me. So I did this:
popupWindow.setTouchInterceptor(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getX() < 0 || motionEvent.getX() > viewWidth) return true;
if (motionEvent.getY() < 0 || motionEvent.getY() > viewHight) return true;
return false;
}
});
If the touch is within the bounds of the popupWIndow, the touch event not consumed (so buttons or scrollviews will work). If the touch is outside the bounds, the touch is consumed and not passed to the popupWindow so it is NOT dismissed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With