Reputation: 482
i use the code like this
mPopupWindow=new PopupWindow();
mPopupWindow.setTouchable(true);
mPopupWindow.setOutsideTouchable(true);
mPopupWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
mPopupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
brush.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mPopupWindow.setContentView(brushView);
mPopupWindow.showAsDropDown(v);
}
});
when i click the button again it will show Attempted to finish an input event but the input event receiver has already been disposed.
it think it because it tirgger the outside and clicklistener
Upvotes: 0
Views: 1447
Reputation: 1085
To make the popup dissapear when clicked on the outside use:
myPopupWindow.setOutsideTouchable(true);
To open and close the popup on clicking the button, put this code in your OnClickListener
:
if(myPopupWindow.isShowing()) {
myPopupWindow.dismiss();
} else {
mPopupWindow.setContentView(brushView);
mPopupWindow.showAsDropDown(v);
}
Upvotes: 1
Reputation: 482
just find a trick use
mPopupWindow=new PopupWindow(new View(mcontext),WindowManager.LayoutParams.WRAP_CONTENT,WindowManager.LayoutParams.WRAP_CONTENT,true);
i don't know why but it works
Upvotes: 0
Reputation: 1857
Please try with below answer:
mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
mPopupWindow.setOutsideTouchable(true);
Upvotes: 1