自定义dialog

public void showDialog() {
View view = getActivity().getLayoutInflater().inflate(
R.layout.mydialog, null);
dialog = new AlertDialog.Builder(getActivity()).setView(view).create();

btn_submit = (Button) view.findViewById(R.id.btn_submit);
btn_cancle = (Button) view.findViewById(R.id.btn_cancle);
et_time = (EditText) view.findViewById(R.id.et_time);
btn_submit.setOnClickListener(this);
btn_cancle.setOnClickListener(this);
dialog.show();
}

public void showDialog(){
dialog=new AlertDialog.Builder(getActivity()).create();
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.mydialog);

btn_submit=(Button) window.findViewById(R.id.btn_submit);
btn_cancle=(Button) window.findViewById(R.id.btn_cancle);
et_time=(EditText) window.findViewById(R.id.et_time);
btn_submit.setOnClickListener(this);
btn_cancle.setOnClickListener(this);
}

原文地址:https://www.cnblogs.com/wangfeng520/p/5111910.html