Given a PopupWindow defined like this:
public class MyWindow extends PopupWindow implements View.OnTouchListener {
MyWindow(View view) {
super(view);
setHeight(view.getMeasuredHeight());
setFocusable(true);
setTouchable(true);
setTouchInterceptor(this);
}
public boolean onTouch(View v, MotionEvent event) {
System.out.println("onTouch()");
return true;
}
}
for some reason, onTouch() is never called.
What am I doing wrong? How can I get the PopupWindow to accept touch events?
As discussed in this answer to a different question, the
PopupWindowneeds to have a backgroundDrawableexplicitly set, even when it has been inflated from XML and doesn’t visually need a background set.I fixed this by adding this line:
to the constructor.