Questions tagged [android-alertdialog]

A subclass of Dialog that can display one, two or three buttons. If you only want to display a String in this dialog box, use the setMessage() method.

A subclass of Dialog that can display one, two or three buttons. If you only want to display a String in this dialog box, use the setMessage() method. If you want to display a more complex view, look up the FrameLayout called "custom" and add your view to it:

FrameLayout fl = (FrameLayout) findViewById(android.R.id.custom);
fl.addView(myView, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));

The AlertDialog class takes care of automatically setting WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM for you based on whether any views in the dialog return true from View.onCheckIsTextEditor(). Generally you want this set for a Dialog without text editors, so that it will be placed on top of the current input method UI. You can modify this behavior by forcing the flag to your desired mode after calling onCreate(Bundle)

Reference

5481 questions
1136
votes
36 answers

How do I display an alert dialog on Android?

I want to display a dialog/popup window with a message to the user that shows "Are you sure you want to delete this entry?" with one button that says 'Delete'. When Delete is touched, it should delete that entry, otherwise nothing. I have written a…
UMAR-MOBITSOLUTIONS
  • 73,009
  • 94
  • 197
  • 273
766
votes
21 answers

How to prevent a dialog from closing when a button is clicked

I have a dialog with EditText for input. When I click the "yes" button on dialog, it will validate the input and then close the dialog. However, if the input is wrong, I want to remain in the same dialog. Every time no matter what the input is, the…
679
votes
28 answers

Dialog throwing "Unable to add window — token null is not for an application” with getApplication() as context

My Activity is trying to create an AlertDialog which requires a Context as a parameter. This works as expected if I use: AlertDialog.Builder builder = new AlertDialog.Builder(this); However, I am leery of using "this" as a context due to the…
gymshoe
  • 7,305
  • 5
  • 17
  • 17
376
votes
17 answers

How to display a Yes/No dialog box on Android?

Yes, I know there's AlertDialog.Builder, but I'm shocked to know how difficult (well, at least not programmer-friendly) to display a dialog in Android. I used to be a .NET developer, and I'm wondering is there any Android-equivalent of the…
Solo
  • 3,912
  • 2
  • 14
  • 8
302
votes
12 answers

How can I display a list view in an Android Alert Dialog?

In an Android application, I want to display a custom list view in an AlertDialog. How can I do this?
user2235726
181
votes
13 answers

How can I change default dialog button text color in android 5

I have many alert dialogs in my app. It is a default layout but I am adding positive and negative buttons to the dialog. So the buttons get the default text color of Android 5 (green). I tried to changed it without success. Any idea how to change…
170
votes
9 answers

Android AlertDialog Single Button

I'd like to have an AlertDialog builder that only has one button that says OK or Done or something, instead of the default yes and no. Can that be done with the standard AlertDialog, or would I have to use something else?
Elec0
  • 2,139
  • 3
  • 15
  • 22
157
votes
6 answers

How to use and style new AlertDialog from appCompat 22.1 and above

I am trying to migrate from default android AlertDialog to the new one included in appCompat-22.1 So far I understand you only have to import android.support.v7.app.AlertDialog package in order to use it. But how can I style it? For example change…
157
votes
3 answers

Android simple alert dialog

I need to show a little text message to the users that clicks a button on my Android app, on IOS I just had to create an AlertView that it's simple to use but with Android i'm struggling because the solution seems x10 times harder. I saw that I need…
LS_
  • 6,162
  • 8
  • 42
  • 82
133
votes
10 answers

"Avoid passing null as the view root" warning when inflating view for use by AlertDialog

I get the lint warning, Avoid passing null as the view root when inflating views with null as parent, like: LayoutInflater.from(context).inflate(R.layout.dialog_edit, null); However, the view is to be used as the content of an AlertDialog, using…
Randy Sugianto 'Yuku'
  • 64,635
  • 54
  • 168
  • 216
125
votes
10 answers

"android.view.WindowManager$BadTokenException: Unable to add window" on buider.show()

From my main activity, I need to call an inner class and in a method within the class, I need to show AlertDialog. After dismissing it, when the OK button is pressed, forward to Google Play for purchase. Things work perfectly for most of the times,…
MSIslam
  • 3,991
  • 5
  • 22
  • 27
122
votes
4 answers

How can I add a third button to an Android Alert Dialog?

The API says that the Alert Dialog can have one, two or three buttons, but the SDK only allows for a positive and negative button. How then can I add a third button?
user180825
109
votes
11 answers

How to implement a custom AlertDialog View

In the Android docs on AlertDialog, it gives the following instruction and example for setting a custom view in an AlertDialog: If you want to display a more complex view, look up the FrameLayout called "body" and add your view to it: FrameLayout fl…
stormin986
  • 7,532
  • 14
  • 37
  • 53
109
votes
14 answers

How can I change the color of AlertDialog title and the color of the line under it

I changed the color of an AlertDialog title using this command alert.setTitle( Html.fromHtml("Set IP Address")); But I want to change the color of the line that appear under the title; how can I do that ? Note: I…
86
votes
8 answers

MaterialComponents theme alert dialog buttons

Recently I switched from support library to com.google.android.material:material:1.0.0 But now I have a problem, in this pages there's a note…
1
2 3
99 100