Shane Smiskol
Shane Smiskol

Reputation: 966

Android - ProgressDialog with a button has too much white space

I'll get straight into my problem; here is what I want the ProgressDialog box to be formatted as (this is an AlertDialog):

And this is my ProgressDialog with no button:

Created using:

dialog = new ProgressDialog(MainActivity.this);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setMessage("Gathering all sent SMS messages...");
dialog.setIndeterminate(true);
dialog.setCanceledOnTouchOutside(false);
dialog.setTitle("Gathering...");
dialog.setCancelable(false);

dialog.show();

However, when I set a button like so:

dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
    //do cancel stuff
        }
    });

It takes up way more white space than it should, and more than a normal dialog.

So does anyone know how to add a button to a ProgressDialog and not have a bunch of whitespace like this? Thanks in advance!

Upvotes: 0

Views: 762

Answers (1)

cagdasalagoz
cagdasalagoz

Reputation: 499

It has nothing to do with your design or code. It is about Google's design. If you check out the Design page for dialogs here. You can see that every dialog with a button has the same amount of space after the content.

But you can try to create your custom dialog and create your buttons yourself. This way you can put your buttons wherever you want.

  1. Create your xml file under res/layouts/xml directory.

  2. Create your dialog like this:

final Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.custom);

Upvotes: 2

Related Questions