I have an AlertDialog
in my application, for which I want to have a background for the whole dialog
, and a background and text color for the 2 buttons. I cannot seem to customise the alertDialog. How can I do it? I want the dialog to look like the image below.
Asked
Active
Viewed 383 times
1

Ian Bell
- 533
- 5
- 18
-
1Look into `MaterialAlertDialogBuilder` – Ben P. Mar 02 '21 at 04:50
-
@BenP. thanks,i checked that out, and that solved my problem! – Ian Bell Mar 02 '21 at 10:26
-
@ADM I used `MaterialAlertDialogBuilder` as suggested by Ben above – Ian Bell Mar 02 '21 at 10:27
2 Answers
1
Hmm, basic step are:
- Create your custom layout
- Create dialog builder and set the custom view. (builder.setView(your_custom_view))
There are a ton of tutorials out there, even here in SOF. Please do a search first.
https://suragch.medium.com/creating-a-custom-alertdialog-bae919d2efa5 https://www.journaldev.com/22153/android-custom-alert-dialog

Lạng Hoàng
- 1,790
- 3
- 17
- 32
1
First, create your layout.xml for the dialog, and then for the example codes to call your dialog is like
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.AlertDialog);
View view = LayoutInflater.from(context).inflate(R.layout.yourlayout, null);
builder.setView(view);
final androidx.appcompat.app.AlertDialog alertDialog = builder.create();
if (alertDialog.getWindow() != null) {
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
}
alertDialog.setCancelable(true);
alertDialog.show();
and if you want to declare your view inside your layout.xml
TextView txexample = view.findViewById(R.id.txexample);

itsmebil
- 155
- 1
- 9