From the official documentation:
A subclass of Dialog that can display one, two or three buttons. If
you only want to display a String in this dialog box, use the
setMessage() method. If you want to display a more complex view, look
up the FrameLayout called “custom” and add your view to it:
FrameLayout fl = (FrameLayout) findViewById(android.R.id.custom);
fl.addView(myView, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
But the problem is that android.R.id.custom presents only in OS from 8 API Level.
How can I make custom AlertDialog if I work with less API Level?
actually what you do is as follows:
first, you create the custom_layout.xml under res/layout.
then you’ll add the next code to your activity
and you can show and dismiss it using
myDialog.show();andmyDialog.dismiss();if you have buttons or other views inside your custom_layout.xml, you can find them by
I hope this helps.