为什么当我想重写onCreateDialog方法?

时间:2018-09-20 02:48:45

标签: android alertdialog

大家好,我想显示一个个性化对话框,但我想 覆盖方法

public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();

// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(inflater.inflate(R.layout.dialog_signin, null))
// Add action buttons
       .setPositiveButton(R.string.signin, new DialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int id) {
               // sign in the user ...
           }
       })
       .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
               LoginDialogFragment.this.getDialog().cancel();
           }
       });
return builder.create();

}

此代码来自android文档,但我想在我的activitymain中覆盖它,但是在建议中却没有出现我想知道为什么的方法?该方法的名称相同,但参数不同

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

不推荐使用Activity类的

onCreateDialog。请改用DialogFragment