android dialog 封装,万能的dialog封装

采用Builder设计模式,打造一个万能的dialog,使用时一句话调用不用再写一大串代码

119882829652

框架图.png

一、搭建框架

创建五个对象类

1.AlertDialog ---- Builder创建

public class AlertDialog extends Dialog {

public AlertDialog(Context context, int themeResId) {

super(context, themeResId);

}

public static class Builder{

}

}

2.AlertController ----AlertParams创建

class AlertController {

public AlertController(AlertDialog alertDialog, Window window) {

}

public static class AlertParams{

}

}

3.DialogViewHelper 创建

public class DialogViewHelper {

public DialogViewHelper(Context context, int layoutResId) {

}

}

4.AlertDialog -----Builder

AlertDialog 构造:

private AlertController mAlert;

public AlertDialog(Context context, int themeResId) {

super(context, themeResId);

mAlert=new AlertController(this,getWindow());

}

Builder 构造:

private final AlertController.AlertParams P;

/**

* Creates a builder for an alert dialog that uses the default alert

* dialog theme.

*

* The default alert dialog theme is defined by

* {@link android.R.attr#alertDialogTheme} within the parent

* {@code context}'s theme.

*

* @param context the parent context

*/

public Builder(Context context) {

this(context,R.style.dialog);

}

/**

* Creates a builder for an alert dialog that uses an explicit theme

* resource.

*

* The specified theme resource ({@code themeResId}) is applied on top

* of the parent {@code context}'s theme. It may be specified as a

* style resource containing a fully-populated theme, such as

* {@link android.R.style#Theme_Material_Dialog}, to replace all

* attributes in the parent {@code context}'s theme including primary

* and accent colors.

*

* To preserve attributes such as primary and accent colors, the

* {@code themeResId} may instead be specified as an overlay theme such

* as {@link android.R.style#ThemeOverlay_Material_Dialog}. This will

* override only the window attributes necessary to style the alert

* window as a dialog.

*

* Alternatively, the {@code themeResId} may be specified as {@code 0}

* to use the parent {@code context}'s resolved value for

* {@link android.R.attr#alertDialogTheme}.

*

* @param context the parent context

* @param themeResId the resource ID of the theme against which to inflate

* this dialog, or {@code 0} to use the parent

* {@code co

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值