Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setCancelable(true) for AlertDialog.Builder doesn't work as expected on samsung

I recently discovered that some of the dialogs I implemented in my app work very well, except on samsung devices.

On every device I tested, the "setCancelable(true)" dismissed the dialog when clicking outside of it, except on a samsung devices.

The samsung devices I tested on are : Samsung Galaxy S3, S4 and Samsung Galaxy Tab 2.

new AlertDialog.Builder(context).setCancelable(true) is the exact code.

Anyone else out there that had this problem? Thank you!

like image 783
kimv Avatar asked Sep 22 '14 11:09

kimv


People also ask

What is AlertDialog builder in Android?

Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue. Android AlertDialog is composed of three regions: title, content area and action buttons.

Which method is used to set in AlertDialog?

setIcon() method is use to set the icon on Alert dialog box.

How do I use AlertDialog builder?

Creating a Custom Layout If you want a custom layout in a dialog, create a layout and add it to an AlertDialog by calling setView() on your AlertDialog. Builder object. By default, the custom layout fills the dialog window, but you can still use AlertDialog. Builder methods to add buttons and a title.

How many button options can you use in creating AlertDialog?

An alert dialog can have maximum three action buttons. If you want the user to accept the action, use Positive action button. It is normally displayed as OK/YES. If the user wants to cancel the action , then you can use Negative action button (NO).


1 Answers

I had the same problem, for any reason in some devices like Samsung S3 the dialog doesn't disappear doing click out side. You can fix it using setCanceledOnTouchOutside method:

AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
AlertDialog dialog = b.create();
dialog.setCanceledOnTouchOutside(true);
dialog.show();

Something like that. I hope to help you.

like image 89
yaircarreno Avatar answered Oct 30 '22 01:10

yaircarreno