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

5697 questions
43
votes
7 answers

Alert Dialog Two Buttons

Hello all i have a simple problem i have a alertDialog and i want it to show two buttons i have searched here but it seems the options before don't work anymore and are deprecated. Anyone know the new way of doing this you can see my code below that…
Matt
  • 1,747
  • 8
  • 33
  • 58
42
votes
2 answers

How to set Single Choice Items inside AlertDialog?

I haven't been able to set a Single Choice list, or a Multiple Choice List inside an AlertDialog. I tried following the examples but I only get a Dialog with a Title, the Ok and Cancel buttons, and no list, and NO message (which I set!). Here is the…
Julian Suarez
  • 4,499
  • 4
  • 24
  • 40
42
votes
4 answers

Displaying multiple lines of text and variables in an AlertDialog using setMessage()

I need to display multiple lines of text in an Alert Dialog. If I use multiple setMessage() methods, only the last setMessage is displayed, as shown below. final AlertDialog alertDialog = new AlertDialog.Builder(this).create(); …
Navigatron
  • 2,065
  • 6
  • 32
  • 61
41
votes
4 answers

How to add an icon before each item in alert dialog?

I am using an AlertDialog (see the below code) and would like to put an image before each text. For example, email icon then text "Email", Facebook icon then text "Facebook", etc. Using the following code, how to add an icon before each text…
UMAR-MOBITSOLUTIONS
  • 77,236
  • 95
  • 209
  • 278
41
votes
5 answers

How to close a Dialog in Android programmatically?

How do I close a Dialog in android programmatically for example by a button? Imagine I have a Dialog with a OK button on it, and want to close it by OK button, but I cant do that! I googled and found nothing useful, and almost all of them for…
Amir Hossein Ghasemi
  • 20,623
  • 10
  • 57
  • 53
40
votes
7 answers

How to resize AlertDialog on the Keyboard display

I have a AlertDialog box with approximately 10 controls (text and TextView) on it. These controls are in a ScrollView with AlertDialog, plus I got 2 buttons positive and negative. The issue I have is when the soft keyboard pops up the two buttons…
Sanj
  • 3,770
  • 6
  • 26
  • 31
40
votes
8 answers

AlertDialog styling - how to change style (color) of title, message, etc

I've breaking my head over this quite a bit. What I need to do is, change the style of all AlertDialogs in my android application - dialog background needs to be white-ish, and text needs to be black-ish. I tried creating a lot of styles, themes,…
Aswin Kumar
  • 5,158
  • 5
  • 34
  • 39
40
votes
6 answers

AlertDialog with EditText, open soft keyboard automatically with focus on EditText doesn't work

I'm trying to get a piece of code work which should focus an EditText in an AlertDialog as soon as it shows and then automatically open the soft keyboard. Instead, it just makes the screen go darker. Builder builder = new Builder(this); final…
40
votes
4 answers

Simplest yes/no dialog fragment

I'd like to make a dialog fragment that asks "Are you sure?" with a "yes/no" reply. I've looked at the documentation and it's really verbose, going all over the place, explaining how to make advanced dialog boxes, but no intact code on making a…
Muz
  • 5,866
  • 3
  • 47
  • 65
38
votes
7 answers

How to put an image in an AlertDialog? Android

I don't know how to put an image into an AlertDialog. I have this code, but i think this is not possible. AlertDialog.Builder alert = new AlertDialog.Builder(MessageDemo.this); ImageView imageView = (ImageView) findViewById(R.id.imageView1); …
fr4n
  • 755
  • 1
  • 8
  • 16
38
votes
1 answer

Android Alert Dialog with one, two, and three buttons

I don't make alerts very often but every time I do it takes me a while to read through the documentation and figure out how to do it. Since I have had to do this a few times now, I am going to write an answer below that I can come back to in the…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
38
votes
10 answers

align AlertDialog buttons to center

I use this codes for Android (Java) programming: public static MessageBoxResult showOk( Context context, String title, String message, String okMessage) { okDialogResult = MessageBoxResult.Closed; // make a handler that throws a…
Babak.Abad
  • 2,839
  • 10
  • 40
  • 74
38
votes
8 answers

Android AlertDialog with rounded corners

I have been trying to make my Alert Dialog with rounded corners but somehow I am not able to. I have tried and I failed. I tried to follow this blog http://blog.stylingandroid.com/archives/271 and made my styles based on that. Btw, to add to my…
36
votes
2 answers

Why does AlertDialog.Builder(Context context) only accepts Activity as a parameter?

In my ongoing learning process (dialog boxes this time), I discovered that this works: AlertDialog.Builder builder = new AlertDialog.Builder(this); While the following doesn't work (fails at runtime with WindowManager$BadTokenException): …
an00b
  • 11,338
  • 13
  • 64
  • 101
36
votes
9 answers

Missing buttons on AlertDialog | Android 7.0 (Nexus 5x)

I am trying to create an AlertDialog but the buttons are not showing. Only seeing this issue in Android 7.0: final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("This app needs location…
Sohail
  • 1,137
  • 2
  • 12
  • 22