VansFannel VansFannel -4 years ago 181
Android Question

AlertDialog or Custom Dialog

I'm developing an Android 2.2 application.

I want to show a text with an Ok butto but I want to add my custom style.

What is the better choice an AlertDialog with a custom layout or a Dialog?

Answer Source

I'd go for AlertDialog:

  • It's easier to implement.
  • The only custom thing you have to do is an XML layout and then inflate it.

AlertDialog dialog = new AlertDialog.Builder(this)
    .setView(getLayoutInflater().inflate(R.layout.custom_dialog, null))

In order to listen for UI events:

View view = getLayoutInflater().inflate(R.layout.custom_dialog, null);
Button btn = (Button)view.findViewById(;
btn.setOnClickListener(blah blah);
AlertDialog dialog = new AlertDialog.Builder(this)

You can check in android dialog docs:

The Dialog class is the base class for dialogs, but you should avoid instantiating Dialog directly. Instead, use one of the following subclasses:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download