Close AlertDialog when window padding area clicked - android

I'm trying to close a dialog on click outside, but when I click on the area of the left or right side of dialog it doesn't get closed. I researched it a bit, and figured out that it's the padding of DecorView that creates that transparent space on sides, but I haven't found any way to make it clickable

Close AlertDialog when window padding area clicked
Sorry, you can't do this. Its not possible AFAIK. You should try with setCanceledOnTouchOutside
Sets whether this dialog is canceled when touched outside the window's
bounds. If setting to true, the dialog is set to be cancelable if not
already set.
dialogOBJ.setCanceledOnTouchOutside(true);

Do you try cancel on outside touch function like this
dialog.setCanceledOnTouchOutside(true);

Try to add this line to your dialog:
dialog.setCanceledOnTouchOutside(true);
And now the dialog will get closed when the user will click the screen.

Try this:
alertDialog.setOnTouchListener{
alertDialog.dismiss()
}

Related

Prevent Dialog Box from being dismissed

There is a Dialog Box, how can I prevent it from being dismissed? I want not only the user enter a username but also prevent him/her from leaving the box empty?
dialog.setCancelable(false);
This function call will make your dialog dismissable by touch on the outside of the dialog. Moreover, you can control the actions of the positive and negative buttons. However if you have custom dialog with edit text in it then you should check the string that you get from edittext when user click the positive or negative button and not call dialog.dismiss(); method if string is empty. Hope it helps.
Try this code, it prevents user from dismissing the dialogue box
myDialog.setCancelable(false);

Handling textview hit bottom in alert dialog

I'm setting a message in a simple alert dialog. I need to know if the user has read all the text inside the dialog or not. Is there any way to set a scroll listener or something in an alert dialog?
Create your custom dialog and then set some listener to your custom View. Here's a good example: http://www.mkyong.com/android/android-custom-dialog-example/
and
https://stackoverflow.com/a/10713501

Android: AlertDialog - User click somewhere else [duplicate]

This question already has answers here:
How to avoid dismissing my progress dialog when the user touches the screen?
(6 answers)
Closed 8 years ago.
I have an Alert-dialog with 2 buttons( Yes/No )
If user click yes or no the alert dialog behave normal and get into on-click method, but if user click or touch somewhere outside of alert dialog it just disappear, and nothing will happen, Is there any way to prevent dialog from disappearing when user clicked somewhere else???
Prevent dismiss dialog box on outside touch use this
dialog.setCanceledOnTouchOutside(false);
Add this line to your AlertDialog..
alertDialog.setCanceledOnTouchOutside(false);
For more read here Dialog cancel
You must give this line.
alertDialog.setCanceledOnTouchOutside(false);
on bottom of the your AlertDialog.
Yes Use
YourAlertDialog.setCanceledOnTouchOutside(false);
use
alertDialog.setCanceledOnTouchOutside(false);
also you can use given below line for a practice that alert dialog can only go away by pressing the buttons
alertDialog.setCancelable(false).
This will make it so it can only go away by pressing the buttons.
I usually use the combination of:
alertDialog.setCancelable(false);
alertDialog.setCanceledOnTouchOutside(false);

android - dismiss spinner when user touches somewhere else

I have an app where the user presses a button and a custom spinner is popped so that the user can choose between nine colors. I want the spinner to be dismissed, when the user touches the background (every place on the sreen except from the spinner). Is this possible?
I tried to add an onTouchListener on the image that covers the background and call
dialog.dismiss();
but it does not work.
My spinner is custom Spinner, set in an xml file and popped with:
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.colorchooser);
Thank you in advance
First of all you should be able to add
dialog.setCanceledOnTouchOutside(true);
to accomplish what you want.
But the dismiss() method should also be working, I would guess that the place your are calling dialog.dismiss() is not reachable at the current moment.

alertdialogbox should popup from the bottom of the screen?

I have an alert dialog box in my application.i want the alert dialog box to pop up from the bottom of the screen.can anyone help me??
Animation Api may be what you are looking for.
check this answer slide animation. Its like a iphone actionsheet sliding from bottom to center of the screen
I had done this customizing a dialog and adding a animated theme to the dialog. Its was so simple just passing the animation to the constructor of the dialog and calling the super function with the theme(Animation) will make this happen. Thankzz for all your help....happy coding....

Categories

Resources