Change the background color of a pop-up dialog

To expand on @DaneWhite’s answer, you don’t have to rely on the built-in themes. You can easily supply your own style: <style name=”MyDialogTheme” parent=”Theme.AppCompat.Light.Dialog.Alert”> <item name=”android:background”>@color/myColor</item> </style> and then apply it in the Builder constructor: Java: AlertDialog alertDialog = new AlertDialog.Builder(getContext(), R.style.MyDialogTheme) … .create(); Kotlin: var alertDialog = AlertDialog.Builder(context, R.style.MyDialogTheme) … .create() This should work … 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.

How to setup Alertbox from BroadcastReceiver

Although you can not show AlertDialog from Receivers because it needs ActivityContext. You have an alternate solution to show an Activity like AlertDialog from Receiver. This is possible. To start Activity as dialog you should set theme of activity in manifest as <activity android:theme=”@android:style/Theme.Dialog” /> Style Any Activity as an Alert Dialog in Android To … Read more

Android Alert Dialog with one, two, and three buttons

One button import android.support.v7.app.AlertDialog; public class MainActivity extends AppCompatActivity { public void showAlertDialogButtonClicked(View view) { // setup the alert builder AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(“My title”); builder.setMessage(“This is my message.”); // add a button builder.setPositiveButton(“OK”, null); // create and show the alert dialog AlertDialog dialog = builder.create(); dialog.show(); } } Two buttons public class … Read more

How to dismiss AlertDialog in android

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(); } });

Get value from DialogFragment [duplicate]

Assuming that you want to foward result to the calling Activity:) try this code snippet: public class QuantityDialogFragment extends DialogFragment implements OnClickListener { private EditText editQuantity; @Override public Dialog onCreateDialog(Bundle savedInstanceState) { editQuantity = new EditText(getActivity()); editQuantity.setInputType(InputType.TYPE_CLASS_NUMBER); return new AlertDialog.Builder(getActivity()).setTitle(R.string.app_name).setMessage(“Please Enter Quantity”) .setPositiveButton(“OK”, this).setNegativeButton(“CANCEL”, null).setView(editQuantity).create(); } @Override public void onClick(DialogInterface dialog, int position) { String … Read more

How to use Dialog Fragment? (showDialog deprecated) Android

You can show your DialogFragment like this: void showDialog() { DialogFragment newFragment = MyAlertDialogFragment.newInstance( R.string.alert_dialog_two_buttons_title); newFragment.show(getFragmentManager(), “dialog”); } In you fragment dialog you should override onCreateDialog and return you instance of simple Dialog, for example AlertDialog. public static class MyAlertDialogFragment extends DialogFragment { public static MyAlertDialogFragment newInstance(int title) { MyAlertDialogFragment frag = new MyAlertDialogFragment(); Bundle … Read more

AlertDialog from within BroadcastReceiver?? Can it be done?

Principal issue: try to avoid placing time consuming functionalities into BroadcastReceiver. It should just receive and initiate further processing in bound Activity/Service. UPDATE: Please check following sources that might be helpful: Similar questions on StackOverflow: How to send data from BroadcastReceiver to an Activity in android? Android SMS receiver not working Android SDK demo example: … Read more