Dismiss Pop Up Window When Back Button Is Pressed
I want to dismiss the pop up window when back button is pressed. I tried with this code: popwindow.setBackgroundDrawable(new BitmapDrawable()); and it works. But in my app, pop sho
Solution 1:
popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
newScaleInAnimation(popupView).animate();
popupWindow.getContentView().setFocusableInTouchMode(true);
popupWindow.getContentView().setOnKeyListener(newView.OnKeyListener() {
@OverridepublicbooleanonKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
popupWindow.dismiss();
returntrue;
}
returnfalse;
}
});
Solution 2:
To disable pop up dismiss when click outside of popwindow set
popwindow.setCanceledOnTouchOutside(false);
and for dismiss it on back button set
popwindow.setCancelable(true);
Solution 3:
Set like this..
popupWindow.setOutsideTouchable(true);
popupWindow.setTouchable(true);
popupWindow.setBackgroundDrawable(newBitmapDrawable()); popupWindow.setTouchInterceptor(newOnTouchListener()
{
@OverridepublicbooleanonTouch(View v, MotionEvent event)
{
if (AppContext.isDebugMode())
Log.d("POPUP_WINDOW", "v: "+v.getTag() + " | event: "+event.getAction());
popupWindow.dismiss(); returntrue;
}
});
Solution 4:
Aside from the setOutsideTouchable(true)
and setFocusable(true)
I had to add
popUpView.setBackgroundDrawable(newBitmapDrawable())
to make it work. This did not change the UI of my popup, but for some magical reason, enabled the back button functionality.
Solution 5:
The code below may be helpfull:
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.showAsDropDown(mParent);
And,the show of the popupWindow (popupWindow.showAsDropDown or popupWindow.showAtLocation )must be called in the end.
Post a Comment for "Dismiss Pop Up Window When Back Button Is Pressed"