首页 > 解决方案 > 在全屏对话框顶部显示片段(alertDialog)

问题描述

我有一个全屏透明警报对话框,它在中心底部显示一些图标,高度和宽度为 match_parent,现在我需要在此警报对话框顶部显示一个片段。

我尝试过以下事情:

现在的问题是

  1. 这是可以实现的
  2. 如果是,那么怎么样?

标签: androidandroid-layoutandroid-alertdialog

解决方案


试试这个代码:

public class DialogFragment extends DialogFragment {
   @Override
   public Dialog onCreateDialog(Bundle savedInstanceState) {
      // Use the Builder class for convenient dialog construction
      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
      builder.setPositiveButton(R.string.fire, new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int id) {
            toast.makeText(this,"enter a text here",Toast.LENTH_SHORT).show();
         }
      })
      .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int id) {
            finish();
         });
         // Create the AlertDialog object and return it
         return builder.create();
      }
   }
}

点击此链接了解更多详情 - https://www.tutorialspoint.com/android/android_alert_dialoges.htm


推荐阅读