警报对话框标题上方有空白

Flo*_*ian 4 android android-alertdialog material-design

我试图添加一个带有标题的简单对话框,但是由于某种原因,它的顶部有一个空白。

我使用的代码是:

builder = new AlertDialog.Builder(getContext(), android.R.style.Theme_Material_Light_Dialog_Alert);
            builder.setTitle("Test")
                    .setMessage("This is a weird dialog")
                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which){
                            dialog.dismiss();
                        }
                    })
                    .create().show();
Run Code Online (Sandbox Code Playgroud)

在装有Android 7.1.1的Nexus 5X上看起来像这样:

在此处输入图片说明

上面应该有这么大的利润吗?

作为我的应用主题的父代,我使用:

parent="@style/Theme.AppCompat.Light.NoActionBar"
Run Code Online (Sandbox Code Playgroud)

bux*_*xik 6

代替

builder = new AlertDialog.Builder(getContext(), android.R.style.Theme_Material_Light_Dialog_Alert);
Run Code Online (Sandbox Code Playgroud)

使用

builder = new AlertDialog.Builder(getContext(), android.R.style.Theme_Material_Light_Dialog_NoActionBar);
Run Code Online (Sandbox Code Playgroud)


Flo*_*ian 2

我通过不使用主题摆脱了它Theme_Material_Light_Dialog_Alertparent="@style/Theme.AppCompat.Light.Dialog.Alert"相反,我作为父母做了一个定制设计。