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

When you are creating the dialog, add something like this to the builder: builder = new AlertDialog.Builder(context); builder.setTitle(“Test”); builder.setIcon(R.drawable.icon); builder.setMessage(“test”); builder.setPositiveButton(“Call Now”, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.setNeutralButton(“Setup”, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { context.startActivity(new Intent(context, Setup.class)); //dialog.cancel(); } }); builder.setNegativeButton(“Exit”, new DialogInterface.OnClickListener() … Read more

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

android.view.WindowManager$BadTokenException: Unable to add window” Problem : This exception occurs when the app is trying to notify the user from the background thread (AsyncTask) by opening a Dialog. If you are trying to modify the UI from background thread (usually from onPostExecute() of AsyncTask) and if the activity enters finishing stage i.e.) explicitly calling finish(), … Read more

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

When creating the AlertDialog you can set a theme to use. Example – Creating the Dialog AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.MyAlertDialogStyle); builder.setTitle(“AppCompatDialog”); builder.setMessage(“Lorem ipsum dolor…”); builder.setPositiveButton(“OK”, null); builder.setNegativeButton(“Cancel”, null); builder.show(); styles.xml – Custom style <style name=”MyAlertDialogStyle” parent=”Theme.AppCompat.Light.Dialog.Alert”> <!– Used for the buttons –> <item name=”colorAccent”>#FFC107</item> <!– Used for the title and text –> <item … Read more

Android simple alert dialog [duplicate]

You would simply need to do this in your onClick: AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create(); alertDialog.setTitle(“Alert”); alertDialog.setMessage(“Alert message to be shown”); alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, “OK”, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.show(); I don’t know from where you saw that you need DialogFragment for simply showing an alert.

Android AlertDialog Single Button

Couldn’t that just be done by only using a positive button? AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(“Look at this dialog!”) .setCancelable(false) .setPositiveButton(“OK”, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //do things } }); AlertDialog alert = builder.create(); alert.show();

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

Here’s a natural way to do it with styles: If your AppTheme is inherited from Theme.MaterialComponents, then: <style name=”AlertDialogTheme” parent=”ThemeOverlay.MaterialComponents.Dialog.Alert”> <item name=”buttonBarNegativeButtonStyle”>@style/NegativeButtonStyle</item> <item name=”buttonBarPositiveButtonStyle”>@style/PositiveButtonStyle</item> </style> <style name=”NegativeButtonStyle” parent=”Widget.MaterialComponents.Button.TextButton.Dialog”> <item name=”android:textColor”>#f00</item> </style> <style name=”PositiveButtonStyle” parent=”Widget.MaterialComponents.Button.TextButton.Dialog”> <item name=”android:textColor”>#00f</item> </style> If your AppTheme is inherited from Theme.AppCompat: <style name=”AlertDialogTheme” parent=”ThemeOverlay.AppCompat.Dialog.Alert”> <item name=”buttonBarNegativeButtonStyle”>@style/NegativeButtonStyle</item> <item name=”buttonBarPositiveButtonStyle”>@style/PositiveButtonStyle</item> </style> <style name=”NegativeButtonStyle” parent=”Widget.AppCompat.Button.ButtonBar.AlertDialog”> … Read more

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

Used below code to display custom list in AlertDialog AlertDialog.Builder builderSingle = new AlertDialog.Builder(DialogActivity.this); builderSingle.setIcon(R.drawable.ic_launcher); builderSingle.setTitle(“Select One Name:-“); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(DialogActivity.this, android.R.layout.select_dialog_singlechoice); arrayAdapter.add(“Hardik”); arrayAdapter.add(“Archit”); arrayAdapter.add(“Jignesh”); arrayAdapter.add(“Umang”); arrayAdapter.add(“Gatti”); builderSingle.setNegativeButton(“cancel”, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int … Read more

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

AlertDialog.Builder really isn’t that hard to use. It’s a bit intimidating at first for sure, but once you’ve used it a bit it’s both simple and powerful. I know you’ve said you know how to use it, but here’s just a simple example anyway: DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)