解决方法
您还可以使用AlertDialog.Builder将布局粘贴到警报对话框中,如下所示:
//Preparing views LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.dialog_layout,(ViewGroup) findViewById(R.id.layout_root)); //layout_root should be the name of the "top-level" layout node in the dialog_layout.xml file. final EditText nameBox = (EditText) layout.findViewById(R.id.name_Box); final EditText phoneBox = (EditText) layout.findViewById(R.id.phone_Box); //Building dialog AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(layout); builder.setPositiveButton("Save",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog,int which) { dialog.dismiss(); //save info where you want it } }); builder.setNegativeButton("Cancel",int which) { dialog.dismiss(); } }); AlertDialog dialog = builder.create();