Dialog对话框

对话框种类:普通对话框,单选对话框,多选对话框,自定义对话框,时间对话框,进度条对话框。

创建过程:创建构建者,设置对话框,创建对话框,显示对话框。

普通对话框:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setIcon(R.mipmap.ic_launcher)
                .setTitle("你好")
                .setMessage("普通对话框")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Toast.makeText(MainActivity.this,"确定",Toast.LENGTH_SHORT).show();
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Toast.makeText(MainActivity.this,"取消",Toast.LENGTH_SHORT).show();
                    }
                });
        AlertDialog alertDialog = builder.create();
        alertDialog.show();

单选对话框:

final String[] strings = new String[]{"江苏","宿迁","泗阳"};
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("单选对话框")
                .setIcon(R.mipmap.ic_launcher)
                .setSingleChoiceItems(strings, 0, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Toast.makeText(MainActivity.this,strings[i],Toast.LENGTH_SHORT).show();
                    }
                })
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Toast.makeText(MainActivity.this,"确定",Toast.LENGTH_SHORT).show();
                    }
                }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Toast.makeText(MainActivity.this,"取消",Toast.LENGTH_SHORT).show();
                }}).create().show();

多选对话框:

final String[] name = new String[]{"你","我","他"};
        final boolean[] flag = new boolean[]{true,false,true};
        AlertDialog.Builder builder  = new AlertDialog.Builder(this);
        builder.setMultiChoiceItems(name, flag, new DialogInterface.OnMultiChoiceClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i, boolean b) {
                flag[i] = b;
                Toast.makeText(MainActivity.this,name[i]+":"+b,Toast.LENGTH_SHORT).show();
            }
        }).setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                String str="";
                for (int i1=0;i1<flag.length;i1++){
                    if (flag[i1]){
                        str=str+name[i1]+",";
                    }
                }
                Toast.makeText(MainActivity.this,str,Toast.LENGTH_SHORT).show();
            }
        }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Toast.makeText(MainActivity.this,"取消",Toast.LENGTH_SHORT).show();
                    }
                });
        AlertDialog alertDialog = builder.create();
        alertDialog.show();

日期对话框:

Calendar calendar = Calendar.getInstance();
        new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
                Toast.makeText(MainActivity.this,i+"年"+(i1+1)+"月"+i2+"日",Toast.LENGTH_SHORT).show();
            }
        },calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH)).show();

时间对话框:

Calendar calendar = Calendar.getInstance();
        new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker timePicker, int i, int i1) {
                Toast.makeText(MainActivity.this,i+"时"+i1+"分",Toast.LENGTH_SHORT).show();
            }
        },calendar.get(Calendar.HOUR_OF_DAY),calendar.get(Calendar.MINUTE),true).show();

进度条对话框:

final ProgressDialog progressDialog = new ProgressDialog(this);
        progressDialog.setMax(100);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressDialog.setMessage("正在下载");
        progressDialog.show();
        new Thread(){
            @Override
            public void run() {
                int progress=0;
                super.run();
                for (int i=0;i<100;i++){
                    try {
                        Thread.sleep(200);
                        progress+=i;
                        progressDialog.setProgress(progress);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }.start();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
超炫Dialog对话框是一种专为手机应用程序设计的界面元素,其设计风格炫目而富有创意。它具有以下几个特点: 首先,超炫Dialog对话框具有丰富多彩的样式和动画效果。通过使用各种鲜艳的颜色和精心设计的动态效果,该对话框能够吸引用户的眼球,增加界面的活力和吸引力。 其次,超炫Dialog对话框提供了多种交互方式。它可以响应不同的用户操作,如点击、滑动、拖动等,从而为用户提供更加自由和灵活的交互体验。此外,该对话框还支持手势识别和语音控制等高级交互功能,进一步提升用户的操作便捷性。 再次,超炫Dialog对话框具备强大的功能和扩展性。它可以用于展示各种类型的信息,如文字、图片、音视频等,并可以根据需要灵活地扩展功能。无论是提示、确认、警告还是错误信息,该对话框都能够满足不同场景的需求。 最后,超炫Dialog对话框还具备良好的兼容性和适配性。它可以适配不同尺寸和分辨率的屏幕,保证在不同设备上都能够正常显示和使用。此外,该对话框还兼容不同的操作系统和平台,如Android、iOS等,使得开发者能够在多个平台上灵活使用。 综上所述,超炫Dialog对话框以其炫目、多彩、交互丰富、功能强大、兼容性强等特点,成为了手机应用程序中不可或缺的重要元素,为用户提供了更加优秀的交互和使用体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值