How to dismiss a DialogFragment when pressing outside the dialog?
DialogFragment.getDialog().setCanceledOnTouchOutside(true); Must be called in onCreateView (as Apurv Gupta pointed out).
DialogFragment.getDialog().setCanceledOnTouchOutside(true); Must be called in onCreateView (as Apurv Gupta pointed out).
Actually there is no any cancel() or dismiss() method from AlertDialog.Builder Class. So Instead of AlertDialog.Builder optionDialog use AlertDialog instance. Like, AlertDialog optionDialog = new AlertDialog.Builder(this).create(); Now, Just call optionDialog.dismiss(); background.setOnClickListener(new OnClickListener() { public void onClick(View v) { SetBackground(); // here I want to dismiss it after SetBackground() method optionDialog.dismiss(); } });
Yes. there are already a bunch of answers, but I’m just going to add one to the end of the list anyway. The problem is that we need to get a reference to the view controller at the base of the hierarchy. As in @Juan Munhoes Junior’s answer, you can walk the hierarchy, but there … Read more
You can call : self.view.window!.rootViewController?.dismiss(animated: false, completion: nil) Should dismiss all view controllers above the root view controller.
I have been struggling with this issue off and on for a long time; your comment on your question solved the problem for me: After both UnexpectedAlertPresentException and NoAlertPresentException are thrown… browser.execute_script(‘alert(“Clearing out past dialogs.”)’) browser.switch_to.alert.accept() As you said in your answer, webdriver is creating a ‘dialog’ when the alert is present. Closing the alert … Read more
For Flutter version 2 or latest : Since Flutter 2 with null safety this is the best way: FocusManager.instance.primaryFocus?.unfocus(); Note: using old ways leads to some problems like keep rebuild states; For Flutter version < 2 : As of Flutter v1.7.8+hotfix.2, the way to go is: FocusScope.of(context).unfocus(); Comment on PR about that: Now that #31909 … Read more
Use myDialogFragment.setTargetFragment(this, MY_REQUEST_CODE) from the place where you show the dialog, and then when your dialog is finished, from it you can call getTargetFragment().onActivityResult(getTargetRequestCode(), …), and implement onActivityResult() in the containing fragment. It seems like an abuse of onActivityResult(), especially as it doesn’t involve activities at all. But I’ve seen it recommended by official google … Read more
To do what you ask you could have the overlay view as an optional, class level property, and try to remove it when the view appears class VC1: UIViewController { var overlayView: UIView? override func viewDidAppear() { super.viewDidAppear() overlayView?.removeFromSuperView() } Or you could use a protocol / delegate pattern to inform VC1 that VC2 was … Read more