Show custom alert dialog in Jetpack Compose

Starting from M3 1.1.0-alpha04 there is an AlertDialog composable function with a slot for content. val openDialog = remember { mutableStateOf(true) } if (openDialog.value) { androidx.compose.material3.AlertDialog( onDismissRequest = { // Dismiss the dialog when the user clicks outside the dialog or on the back // button. If you want to disable that functionality, simply use … Read more

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

How to change alert dialog header divider color android

You can actually change color of AlertDialog title by a very simple hack: public static void brandAlertDialog(AlertDialog dialog) { try { Resources resources = dialog.getContext().getResources(); int color = resources.getColor(…); // your color here int alertTitleId = resources.getIdentifier(“alertTitle”, “id”, “android”); TextView alertTitle = (TextView) dialog.getWindow().getDecorView().findViewById(alertTitleId); alertTitle.setTextColor(color); // change title text color int titleDividerId = resources.getIdentifier(“titleDivider”, “id”, … Read more

Android Alert dialog from inside an intent service

Need Activity for display AlertDialog, because we can’t display Dialog from any Service Solution. Create Activity as Dialog Theme and start that Activity from Service. Just need to register you Activity in menifest.xml like as below android:theme=”@android:style/Theme.Dialog” or android:theme=”@android:style/Theme.Translucent.NoTitleBar” MyDialog.java public class MyDialog extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final AlertDialog … Read more

Android AlertDialog with rounded corners

You can do it using the following code: CustomDialog.java: public class MainActivity extends Activity{ private static final int ALERT_DIALOG = 1; @Override public void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); setContentView( R.layout.main ); ( (Button) findViewById( R.id.button1 ) ) .setOnClickListener( new OnClickListener() { public void onClick( View v ) { showDialog( ALERT_DIALOG ); … Read more

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

Ok I managed to get it working: Builder builder = new Builder(this); final EditText input = new EditText(this); builder .setTitle(R.string.dialog_title_addsubject) .setMessage(R.string.dialog_addsubject) .setView(input) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String value = input.getText().toString(); if (input.getText().toString().trim().length() == 0) { Toast.makeText(Main.this, R.string.input_empty, Toast.LENGTH_SHORT).show(); } else { db.insertSubject(value); getData(); } InputMethodManager imm = (InputMethodManager) … Read more

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

You need custom ListAdapter to add your image. One way is to subclass the ArrayAdapter (used by default by the AlertDialog). Here is an example: final Item[] items = { new Item(“Email”, android.R.drawable.ic_menu_add), new Item(“Facebook”, android.R.drawable.ic_menu_delete), new Item(“…”, 0),//no icon for this one }; ListAdapter adapter = new ArrayAdapter<Item>( this, android.R.layout.select_dialog_item, android.R.id.text1, items){ public View … Read more

Changing font size into an AlertDialog

You can actually get access to the message’s TextView pretty easily, and then change it’s size. I tested with a bigger size, but you could use whatever size you want. The text will scroll nicely as it already does. The view’s id is android.R.id.message AlertDialog dialog = new AlertDialog.Builder(this).setMessage(“Hello world”).show(); TextView textView = (TextView) dialog.findViewById(android.R.id.message); … Read more

how to get spinner values in textview

Define custom interface which is given callback from multiple item selection dialog. public interface MultipleItemSelectListener { public void onSelected(String value,String ids); } Custom Multiple item selection dialog method. Parameters Content : your activity content reference. title : dialog title. jsonArrayString : your jsonarray response as string. MultipleItemSelectListener : custom on item selected listener. public void … Read more