自定义Dialog,仿造别人写的,内容有些不同,完全自己定制

本文介绍如何仿照系统AlertDialog.Builder创建自定义Dialog。通过更改类名为MyDialog.Builder,可以轻松定制个人化的Dialog。关键在于调整XML布局文件ar_shape_dottedrect_message.xml以及应用特定的Dialog样式,更多细节可在作者的其他日志中找到。
摘要由CSDN通过智能技术生成


仿写系统的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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值