安卓开发-5种常见对话框dialog_box

常见对话框1:确认对话框


public void confirm_dialog(View view){
        AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this);
        builder.setTitle("警告");
        builder.setMessage("对话框是否弹出?");
        builder.setNegativeButton("否",null);
        builder.setPositiveButton("是", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Toast.makeText(MainActivity.this,"GG",0).show();
            }
        });
        builder.show();
    }

常见对话框2:单选对话框


public void radio_dialog(View view){

        builder.setTitle("请选择你的性别");
        final String[] items={"男","女","人妖"};
        builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Toast.makeText(MainActivity.this,"你选择的性别是:"+items[i],0).show();
            }
        });
        builder.setNegativeButton("取消选择",null);
        builder.show();
    }

常见对话框3:多选对话框


public void multi_dialog(View view){
    builder.setTitle("请选择你喜欢的老师");
    final String[] items={"苍井空","波多野结衣","吉泽明步"};
    final boolean[] checkeditems={false,false,false};
    builder.setMultiChoiceItems(items, checkeditems, new DialogInterface.OnMultiChoiceClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i, boolean b) {
            Toast.makeText(MainActivity.this,"你选择的水果是:"+items[i]+b,0).show();
        }
    });
    builder.setNegativeButton("取消选择",null);
    builder.show();
}

常见对话框4:circle对话框


public void circle_dialog(View view){
        ProgressDialog pd=new ProgressDialog(this);
        pd.setMessage("正在加载你的老师");
        pd.show();
    }

常见对话框5:进度条对话框


public void progress_dialog(View view){
        final ProgressDialog pd=new ProgressDialog(this);
        pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        pd.setMax(100);
        new Thread(){
            public void run(){
                for (int i=0;i<=100;i++){
                    try {
                        Thread.sleep(300);
                        pd.setProgress(i);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                pd.dismiss();
            }
        }.start();
        pd.setMessage("正在加载你的老师");
        pd.show();
    }



展开阅读全文

没有更多推荐了,返回首页