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
87
votes
11 answers

Flutter - Auto size AlertDialog to fit list content

I need to load list cities dynamically from rest webservice and let user choose a city from alert dialog. My code: createDialog() { fetchCities().then((response) { showDialog( context: context, builder: (BuildContext…
user1209216
  • 7,404
  • 12
  • 60
  • 123
82
votes
9 answers

AlertDialog's setCancelable(false) method not working

I had created an AlertDialog which is working fine. It is disappearing, if I press: 1) escape keyboard button or 2) back button using mouse To make it stay focused even on above stated conditions, I had added '.setCancelable(false)' statement…
lupchiazoem
  • 8,026
  • 6
  • 36
  • 42
74
votes
10 answers

Change the background color of a pop-up dialog

I wrote android code that shows a pop-up dialog but I want to change the background color from black to white , and then the color of the writing. This is the dialog's code: mPrefs = PreferenceManager.getDefaultSharedPreferences(this); Boolean…
Rick
  • 3,943
  • 6
  • 33
  • 45
73
votes
2 answers

DialogFragment advantages over AlertDialog

When developing an Android app, I've read that it's recommended to use DialogFragment instead of using directly an AlertDialog to show alerts and confirmations. This is done, for example, on DialogFragment's Documentation:…
72
votes
8 answers

android activity has leaked window com.android.internal.policy.impl.phonewindow$decorview Issue

I am working with Android application to show network error. NetErrorPage.java package exp.app; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import…
Ponmalar
  • 6,871
  • 10
  • 50
  • 80
71
votes
3 answers

What does it mean that a Listener can be replaced with lambda?

I have implemented an AlertDialog with normal negative and positive button click listeners. When I called new DialogInterface.OnClickListener() it was showing me a suggestion saying: Anonymous new DialogInterface.OnClickListener() can be replaced…
Kavin Prabhu
  • 2,307
  • 2
  • 17
  • 36
67
votes
9 answers

How to display AlertDialog in a Fragment?

I want to display an alert dialog in my app. I am using fragments. I tried the below code to do this: AlertDialog ad = new AlertDialog.Builder(context) .create(); ad.setCancelable(false); ad.setTitle(title); …
andro-girl
  • 7,989
  • 22
  • 71
  • 94
61
votes
3 answers

Getting default padding for AlertDialog

I need to make a AlertDialog with a custom view. The message of a AlertDialog has a default padding but when I set a view it has no padding, I want to get the same padding as the default as the message. I'm using a style that extends Holo theme (if…
Ari M
  • 1,386
  • 3
  • 18
  • 33
60
votes
5 answers

Android-Is it possible to add a clickable link into a string resource

I usually set up some kind of AlertDialog to fire off when a user first uses one of my apps and I explain how to use the app and give an overall introduction to what they just downloaded. I also usually load my strings from a strings.xml file. What…
James andresakis
  • 5,335
  • 9
  • 53
  • 88
60
votes
8 answers

AlertDialog with custom view: Resize to wrap the view's content

I have been having this problem in an application I am building. Please ignore all of the design shortcomings and lack of best practice approaches, this is purely to show an example of what I cannot solve. I have DialogFragment which returns a basic…
59
votes
5 answers

How to set part of text to bold when using AlertDialog.setMessage() in Android?

How to set part of text to Bold when using AlertDialog's setMessage()? Adding and to my String doesn't work.
SuitUp
  • 3,112
  • 5
  • 28
  • 41
58
votes
4 answers

How to add a check box to an alert dialog

Currently when the user opens my app, an AlertDialog opens, asking them if they would like to upgrade to the pro version. I need to add a CheckBox to the AlertDialog that will make the app no longer show the AlertDialog when the user opens the…
Lucas Faudman
  • 593
  • 1
  • 5
  • 5
58
votes
9 answers

Show custom alert dialog in Jetpack Compose

I am searching how create custom dialog in Jetpack Compose. In XML or Material Design we can create easily custom Dialog in which we can take user input, radio button etc. but i am not finding such thing in Jetpack Compose.
57
votes
7 answers

Android Image Dialog/Popup

Is it possible to have just an image popup/come-up in an Android application? It's similar to an overriding the normal view of an AlertDialog so that it contains just an image and nothing else. SOLUTION: I was able to find an answer thanks to…
Abhijit
  • 4,853
  • 3
  • 30
  • 33
56
votes
8 answers

AlertDialog's items not displayed

I create an AlertDialog with an AlertDialog.Builder and set some items with setItems(). The dialog is shown but I cannot see any of the items. All I see is the message. final CharSequence[] items = {"Red", "Green", "Blue"}; AlertDialog.Builder…
Allan Mermod
  • 806
  • 1
  • 8
  • 16