Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/235.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 标题在AlertDialog中显示2次_Android_Android Alertdialog - Fatal编程技术网

Android 标题在AlertDialog中显示2次

Android 标题在AlertDialog中显示2次,android,android-alertdialog,Android,Android Alertdialog,我试图在android中显示AlertDialog。问题是对话框的标题出现了两次。我希望它只显示一个标题?我怎么做 这就是对话框的外观 这就是我显示对话框的方式 AlertDialog alertDialog = new AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog).create(); alertDialog.setTitle(R.string.ttl_alrt_d

我试图在android中显示AlertDialog。问题是对话框的标题出现了两次。我希望它只显示一个标题?我怎么做

这就是对话框的外观

这就是我显示对话框的方式

   AlertDialog alertDialog = new AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog).create();
                    alertDialog.setTitle(R.string.ttl_alrt_dlg_dont_asked_again);
                    alertDialog.setMessage("AI bifat nu ma mai intreba asa ca mergi in setari");
                    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();


                                    actv.finish();
                                    //ActivityCompat.requestPermissions(actv,
                                      //      new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                                        //    MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
                                }
                            });
                    alertDialog.show();
删除此行-:

alertDialog.setTitle(R.string.ttl_alrt_dlg_dont_asked_again);
试试这个:

AlertDialog alertDialog = new AlertDialog.Builder(this)
            .setTitle("title")
            .setMessage("AI bifat nu ma mai intreba asa ca mergi in setari")
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialog.dismiss();
                    actv.finish();
                }
            })
            .create();
    alertDialog.show();

这是主题、材料和对话问题。因此,您必须通过创建样式自定义自己的对话框

看到这个有用的答案了吗


而这个完整的答案

看起来像是由于android.R.style.Theme\u Material\u对话框,第一个标题是动作栏

解决方案

1.只需使用它而不带任何风格即可。它将显示在材料设计外观无论如何

2.或者您可以使用
android.R.style.Theme\u Material\u Dialog\u NoActionBar

  AlertDialog alertDialog = new AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog_NoActionBar).create();
  alertDialog.setTitle(R.string.ttl_alrt_dlg_dont_asked_again);
  alertDialog.setMessage("AI bifat nu ma mai intreba asa ca mergi in setari");
  alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                }
            });
    alertDialog.show();

在使用AppCompatDialogFragment时遇到类似问题。最终使用如下方式避免,标题显示两次:

<style name="dialogfrag_title" parent="Theme.MaterialComponents.Light.Dialog">
    <item name="android:windowNoTitle">true</item>
    <item name="android:padding">@dimen/lyt_margin</item>
    <item name="android:windowBackground">@color/appBackground</item>
</style>

那么“所需权限”文本将从何处显示?@ShivamOberoi its
setTitle
而不是
addTitle
。因此,删除这些内容不会对使用各种操作系统的各种设备起作用?我认为这是由于android.R.style.Theme\u Material\u对话框的这种风格,您的代码应该可以正常工作。但正如它所显示的,这两件事可能会搞砸。一个是你的主题。另一个是在创建对话框后设置标题。所以,你可以试试这个。@Sayem的答案也是很好的。但我认为这是正确的答案,因为它保留了材料的外观。
        getDialog().setTitle("About "+ user.name());