Change dialog button color

You can use the MaterialAlertDialogBuilder provided by the Material Components library which allows the creation of a Material AlertDialog. Just use: new MaterialAlertDialogBuilder(MainActivity.this, R.style.MyThemeOverlay_MaterialComponents_MaterialAlertDialog) .setTitle(“Dialog”) .setMessage(“Lorem ipsum dolor ….”) .setPositiveButton(“Ok”, /* listener = */ null) .setNegativeButton(“Cancel”, /* listener = */ null) .show(); Then define your custom style, using the buttonBarPositiveButtonStyle and buttonBarNegativeButtonStyle attributes: <!– Alert … 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 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(); } });

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

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

Custom layout for Spinner item

I have this and this with these code of xml xml for adapter named spinadapt.xml <?xml version=”1.0″ encoding=”utf-8″?> <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”30dp” android:background=”#fff” > <TextView android:id=”@+id/tvCust” android:layout_width=”wrap_content” android:layout_height=”30dp” android:layout_toLeftOf=”@+id/radioButton1″ android:gravity=”left|center_vertical” android:textColor=”#000″ android:textSize=”15sp” /> <RadioButton android:layout_width=”wrap_content” android:layout_height=”30dp” android:layout_alignParentRight=”true” /> </RelativeLayout> and main layout named activity_main.xml <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent”> <TextView android:id=”@+id/spinner1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_alignParentLeft=”true” android:layout_alignParentTop=”true” … 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