如何删除警报对话框标题栏

Sun*_*Sun 22 android android-alertdialog

我按照此代码创建自定义对话框但我没有得到如何删除对话框标题栏?

  AlertDialog alertDialog;

   @Override
   protected Dialog onCreateDialog(int id) {

      AlertDialog dialogDetails = null;

      switch (id) {
      case DIALOG_LOGIN:

       LayoutInflater inflater = LayoutInflater.from(this);
       View dialogview = inflater.inflate(R.layout.dialog_layout, null);

           AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(this);
           dialogbuilder.setTitle("Login");
           dialogbuilder.setView(dialogview);
           dialogDetails = dialogbuilder.create();

           break;
          }

      return dialogDetails;
     }

     @Override
     protected void onPrepareDialog(int id, Dialog dialog) {

      switch (id) {
      case DIALOG_LOGIN:
      alertDialog = (AlertDialog) dialog;

      .......

}
Run Code Online (Sandbox Code Playgroud)

我知道要删除警报对话框的标题区域,我们必须使用 requestWindowFeature(Window.FEATURE_NO_TITLE);

但不知道我必须放在哪里?

Nir*_*tel 29

如果您不想在警告对话框中使用标题栏,则只需从代码中删除以下行.

dialogbuilder.setTitle("Login");
Run Code Online (Sandbox Code Playgroud)

如果仍然无法正常工作,请添加以下行.

dialogbuilder.requestWindowFeature(Window.FEATURE_NO_TITLE);
Run Code Online (Sandbox Code Playgroud)


小智 20

使用dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);之前dialog.setContentView(R.layout.logindialog);,您可以隐藏Dialog标题.


Yog*_*thi 5

使用 dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);