Customizing dialog by extending Dialog or AlertDialog Customizing dialog by extending Dialog or AlertDialog android android

Customizing dialog by extending Dialog or AlertDialog


In the constructor of your class that extends Dialog call super(context, R.style.CustomDialog); I've done this many times to create custom dialogs with specific themes.

However if the theme is the only thing about the Dialog that you want to change, you could try just instantiating an instance of the Dialog class and pass it the theme ID like Dialog dialog = new Dialog(context, R.style.CustomDialog);

An example of extending Dialog:

public class MyDialog extends Dialog{    public MyDialog(final Context context)    {        // Set your theme here        super(context, R.style.MyDialogTheme);        // This is the layout XML file that describes your Dialog layout        this.setContentView(R.layout.myDialogLayout);      }}

The rest of the code you will add to this class is going to be pretty much exactly like what you would write in an Activity class.