Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android “警报”对话框的标题上方有空白_Android_Material Design_Android Alertdialog - Fatal编程技术网

Android “警报”对话框的标题上方有空白

Android “警报”对话框的标题上方有空白,android,material-design,android-alertdialog,Android,Material Design,Android Alertdialog,我试图添加一个带有标题的简单对话框,但由于某些原因,它的顶部有一个空白 我使用的代码是: builder = new AlertDialog.Builder(getContext(), android.R.style.Theme_Material_Light_Dialog_Alert); builder.setTitle("Test") .setMessage("This is a weird dialog")

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

我使用的代码是:

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();
在我的Nexus 5X和Android 7.1.1上看起来是这样的:

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

作为我的应用程序主题的父级,我使用:

parent="@style/Theme.AppCompat.Light.NoActionBar"

尝试更改对话框主题,请参见:


干杯

我通过不使用
主题、材质、灯光、对话框、警报主题来摆脱它。相反,我用
parent=“@style/Theme.AppCompat.Light.Dialog.Alert”
作为父项进行了自定义设计。

builder = new AlertDialog.Builder(getContext(), android.R.style.Theme_Material_Light_Dialog_Alert);
使用


我也有这个问题。我通过将导入内容从
android.support.v7.app.AlertDialog
更改为
android.app.AlertDialog

请发布相关主题代码来解决此问题。我用我的应用主题的父级更新了我的帖子。除此之外,我没有对特定主题进行任何更改。谢谢,建议的答案删除了顶部的空白,但使整个对话框变小,并切断了消息。我只是通过不使用主题\材质\灯光\对话框\警报主题来解决了这个问题,而是编写了一个自定义设计。如果答案删除了空格,请接受我的答案,因为解决这个问题(空白)非常适合您对默认对话框主题非常满意的情况,而不是为未使用的功能留下过多的间隙。
builder = new AlertDialog.Builder(getContext(), android.R.style.Theme_Material_Light_Dialog_NoActionBar);