简体   繁体   English

如何在Android列表警报对话框中删除多余的空间

[英]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();

带有单个选项的示例警报对话框

Suggest me to solve this. 建议我解决这个问题。

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. 您可以拥有自己的对话框布局(请参阅文档),但是我建议保持原样,因为此对话框在HC / ICS / JB上的外观会有所不同,因此,调整其外观与在其他版本的android上一样是个坏主意它可能看起来有所不同。 It's just the way OS does it. 这只是OS的方式。 Leave it is my advice. 离开这是我的建议。

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: 根据此处的文档,遵循android.R.style.Theme_DeviceDefault_Panel的用法:

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. 它使窗口浮动并具有透明背景,并关闭窗口后面的调光。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM