Android 对话框AlertDialog和AlertDialog.Builder两者的区别

Android中的AlertDialog是常用对话框,通常通过构造函数的保护权限限制直接创建,而是使用AlertDialog.Builder进行构建。Builder允许设置标题、消息、按钮等。创建对话框DEMO展示了如何使用Builder并设置监听。自定义布局时,仍需用Builder的create方法生成AlertDialog。总结来说,仅使用Builder可完成默认布局对话框,自定义布局则需通过create()方法。
摘要由CSDN通过智能技术生成

AlertDialog也是Android系统当中最常用的对话框之一。 程序员可以给AlertDialog对话框设置相应的信息。比如title,massage,setSingleChoiceItems,setPositiveButton,setNegativeButton等等。。

但不能直接通过AlertDialog的构造函数来生产一个AlertDialog。查看源码发现AlertDialog所有的构造方法都是protected的。
AlertDialog构造方法源码如下:

 protected AlertDialog(Context context) {
        super((Context)null, false, (OnCancelListener)null);
        throw new RuntimeException("Stub!");
    }

    protected AlertDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super((Context)null, false, (OnCancelListener)null);
        throw new RuntimeException("Stub!");
    }

    protected AlertDialog(Context context, int themeResId) {
        super((Context)null, false, (OnCancelListener)null);
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值