1

In the material design documentation it says the content padding of the dialog's text should be 24dp, but if you construct a simple AlerDialog with following code there isn't any bottom padding as you can see in the screenshot.

AlertDialog

    public class MainActivity extends android.support.v7.app.AppCompatActivity { 

      @Override
      public void onCreate(final Bundle savedInstanceState) {

      final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(this);
      builder.setTitle("title");
      builder.setMessage("asdf asöldkfasölkdf öasdklfjöa aösdkföa sdköf masjdö lmasjködf mjaösk maöskd mjaösk fmaöskmaöskmföasföalk maölskjd möaslkd möas mjaös m").setCancelable(true)
             .setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(final DialogInterface dialog, final int id) {
                      dialog.cancel();
                  }
              }).setOnCancelListener(new OnCancelListener() {
                 @Override
                 public void onCancel(final DialogInterface dialog) {
                   MainActivity.sMessageDialogId = 0;
                 }
      });
      builder.show();
     }
    }
David
  • 3,971
  • 1
  • 26
  • 65
  • Use android.support.v7.app.AlertDialog instead of android.app.AlertDialog. Check http://stackoverflow.com/questions/26455919/material-design-not-styling-alert-dialogs/29810469#29810469 – Gabriele Mariotti Apr 22 '16 at 19:47
  • It already is the support version – David Apr 26 '16 at 11:30
  • So ridiculous that so much of the framework itself doesn't follow the Material guidelines. Did you ever find a solution without having to set a custom view on the dialog builder? Many of the other padding dimensions don't quite match up to the guidelines either. – Tony Chan Jul 13 '16 at 06:37

2 Answers2

2

Please use the following the code to check the version compatibility,

AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder = new android.app.AlertDialog.Builder(getActivity(),android.R.style.Theme_Material_Light_Dialog_Alert);
} else {
        builder = new android.app.AlertDialog.Builder(getActivity());
}
SLePort
  • 15,211
  • 3
  • 34
  • 44
Dharmaraj
  • 1,256
  • 13
  • 12
0

Try this builder.setPadding(24, 24, 24, 24);

Piyush
  • 18,895
  • 5
  • 32
  • 63
Milos Lulic
  • 627
  • 5
  • 22