仿写系统的AlertDialog.Builder,如需定制自己的Dialog,直接改类名即可,如MyDialog.Builder builder = new MyDialog.Builder();
MyDialog.java
public class MyDialog_Common extends Dialog {
public MyDialog_Common(Context context) {
super(context);
}
public MyDialog_Common(Context context, int theme) {
super(context, theme);
}
public static class Builder {
private Context context;
private View contentView;
//对话框内容
private String dialogPrompte;
//提示信息
private String dialogTitle;
//对话框标题
private int dialogIcon;
//对话框图标
private String dialogMessage;
//对话框信息
private String FirstButtonText;
//第一个按钮
private String SecondButtonText;
//第二个按钮
private String ThirdButtonText;
//第三个按钮
private DialogInterface.OnClickListener FirstButtonListener, SecondButtonListener,ThirdButtonListener;
public Builder(Context context) {
this.context = context;
}
public Builder setContentView(View v) {
this.contentView = v;
return this;
}
public Builder setIcon(int imageID) {
this.dialogIcon = imageID;
return this;
}
public Builder setTitle(String title) {
this.dialogTitle = title;
return this;
}
public Builder setPromote(String promote) {
this.dialogPrompte = promote;
return this;
}
public Builder setTitle(int title) {
this.dialogTitle = context.getString(title);
return this;
}
public Builder setMessage(String message) {
this.dialogMessage = message;
return this;
}
public Builder setMessage(int message) {
this.dialogMessage = context.getString(message);
return this;
}
public Builder setFirstButton(String firstButText,DialogInterface.OnClickListener FirstButtonListener) {
this.FirstButtonText = firstButText;
this.FirstButtonListener = FirstButtonListener;
return this;
}
public Builder setSecondButton(String SecondButtonText, DialogInterface.OnClickListener SecondButtonListener) {
this.SecondButtonText = SecondButtonText;
this.SecondButtonListener = SecondButtonListener;
return this;
}
public Builder setFirstButton(int FirstButtonText,DialogInterface.OnClickListener FirstButtonListener) {
this.FirstButtonText = context.getString(FirstButtonText);
this.FirstButtonListener = FirstButtonListener;
return this;
}
public Builder setSecondButton(int SecondButtonText, DialogInterface.OnClickListener SecondButtonListener) {
this.SecondButto