343N
343N

Reputation: 296

Remove top padding from AlertDialog?

So I made a AlertDialog and there's this nasty top padding on my AlertDialog for some reason using the default Android lollipop+ theme and I can't figure out how to edit it/get rid of it.

Here's the code that I use to produce the AlertDialog

AlertDialog.Builder builder;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                builder = new AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog_Alert);
            } else {
                builder = new AlertDialog.Builder(this);
            }
            builder.setTitle("Found corrupted files")
                    .setMessage("We've found " + count + " images that are either missing or " +
                            "corrupt. Should we remove these entries from the list?")
                    .setPositiveButton("Yeah", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface d, int i) {
                            MainActivity.this.removeCorruptedImages();
                            d.cancel();
                        }
                    })
                    .setNegativeButton("No", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface d, int i) {
                            d.cancel();
                        }
                    })
                    .setIcon(R.drawable.ic_warning_white_24dp);

            AlertDialog al = builder.create();
            al.show();

And it produces this: enter image description here

I want to get rid of that padding/blank space above the title.

Upvotes: 3

Views: 2365

Answers (2)

Meikiem
Meikiem

Reputation: 1936

Just try this line before showing your AlertDialog

AlertDialog al = builder.create(); al.requestWindowFeature(Window.FEATURE_NO_TITLE); al.show();

Upvotes: 6

user6490462
user6490462

Reputation:

Did you tried to set view spacing like this :

a1.setView(View view, int viewSpacingLeft, int viewSpacingTop, int viewSpacingRight, int viewSpacingBottom)

Upvotes: 2

Related Questions