Dialog样式

Dialog分三个部分:标题(可以不设置),类容,动作按钮(可以不设置)
这里写图片描述

Dialog中actions分为三种:
通过builder.setXXXButton("buttonText",onClickedListener)的方式设置

  • 确定按钮(PositiveButton)builder.setPositiveButton()
  • 取消按钮(NegativeButton) builder.setNegativeButton()
  • 中性按钮(NeutralButton)builder.setNeutralButton()用于除了确认和取消外的按钮(如了解更多,或者稍后提醒等)
    这里写图片描述 这里写图片描述

Alert Dialog

1.通过工厂模式来创建AlertDialog
AlertDialog.Builder builder = new AlertDialog.Builder(context);
AlertDialog alertDialog = builder.create()设置好dialog的单个部分后,通过builder.create()方法来创建AlertDialog对象
alertDialog.show()显示AlertDialog
dialog.dismiss();Dialog消失
alerrtDialog.cancel()取消AlertDialog

2.设置标题栏
builder.setTitle("DialogTitle");(title)
builder.setIcon(R.drawable.icon3); (icon)
builder.setCustomTitle(LayoutInflater.from(getContext()).inflate(R.layout.title, null));设置自定义布局View的标题

3.设置正文类容和布局
a. 文本确认对话框
builder.setMessage("message");(content的文本类容)
这里写图片描述

b.传统单选对话框(一般传统的单选框)
bulider.setItems()方法添加单选list
这里写图片描述

c.复选对话框或者Radio单选对话框
builder.setMultiChoiceItems()复选对话框
builder.setSingleChoiceItems()Radio单选对话框

这里写图片描述 这里写图片描述

4.自定义AlertDialog的Content视图布局
        LayoutInflater inflater = LayoutInflater.from(getContext());
        View view = inflater.inflate(dialog, null);
        builder.setView(view);//将自定义的View设置为dialog的view

这里写图片描述

5.自定义AlertDialog的actionButton的属性
AlertDialog alertDialog = builder.create();//获得alertDialog的实例
//为alertDialog设置对话框显示监听时间,当alertDialog调了Show()方法时系统会自动调用该方法
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                AlertDialog alertDialog = ((AlertDialog) dialog);
                Button button = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
                Log.i("wendy", "button:" + button);
                button.setTextColor(getResources().getColor(R.color.colorSelected));
                button.setBackgroundColor(getResources().getColor(R.color.colorAccent));
                button.setTextSize(20);
            }
        });//只有当alertDialog调用了show()之后才能通过改方法得到actionButton的实例,来该变button的显示属性
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值