Sankar
Sankar

Reputation: 1691

how to remove extra space in android list alert dialog

I am trying to display sample alert dialog with single choice items and facing problem with extra space after end of the list.

Here is my code

final CharSequence[] items = {"Red", "Green", "Blue"};

        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle("Pick a color");
        builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                Toast.makeText(context, items[item], Toast.LENGTH_SHORT).show();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();

sample alert dialog with single choice items

Suggest me to solve this.

Upvotes: 0

Views: 1462

Answers (2)

Tejas Sherdiwala
Tejas Sherdiwala

Reputation: 769

I had been facing a similar issue when I had build the custom alert dialog. In order to address the issue, I had to use theme to get rid of remaining spaces. Following is the code that I had followed:

private Dialog getCustomDialog() {
      AlertDialog.Builder builder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Panel);
      AlertDialog dialog = builder.create();
      dialog.setView(dialogView, 0, 0, 0, 0);
      return dialog;
    }

As per the documentation here the usage of android.R.style.Theme_DeviceDefault_Panel is followed:

This removes all extraneous window decorations, so you basically have an empty rectangle in which to place your content. It makes the window floating, with a transparent background, and turns off dimming behind the window.

Upvotes: 0

Marcin Orlowski
Marcin Orlowski

Reputation: 75629

You can have your own dialog layout (see docs), but I'd suggest to leave it as is, as this dialog will look differently on HC/ICS/JB, so tweaking its look is quite bad idea as on other versions of android it may look different. It's just the way OS does it. Leave it is my advice.

Upvotes: 1

Related Questions