对话框

1 提示对话框
权限
代码 AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Put your question here?")
       .setCancelable(false)
       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                // put your code here
           }
       })
       .setNegativeButton("No", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
            // put your code here 
            dialog.cancel();
           }
       });
AlertDialog alertDialog = builder.create();
alertDialog.show();

2 进程对话框
权限
代码 ProgressDialog dialog = ProgressDialog.show(this, "Your Title", "Put your message here", true);

3 进程栏对话框
权限
代码 ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMax(PROGRESS_MAX);
progressDialog.setMessage("Put your message here");
progressDialog.setCancelable(false);
progressDialog.incrementProgressBy(PROGRESS_INCREMENT);

4 日期选取器对话框
权限
代码 // Define the date picker dialog listener, which will be called after
// the user picks a date in the dialog displayed
DatePickerDialog.OnDateSetListener datePickerDialogListener =
    new DatePickerDialog.OnDateSetListener() {
        public void onDateSet(DatePicker view, int year, 
                              int monthOfYear, int dayOfMonth) {
            // put your code here 
         // update your model/view given with the date selected by the user
        }
    };
// Get the current date
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
// Create Date Picker Dialog
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
  datePickerDialogListener,
  year, month, day)
// Display Date Picker Dialog
datePickerDialog.show();

5 时间选取器对话框
权限
代码 // Define the date picker dialog listener, which will be called after
// the user picks a time in the dialog displayed
TimePickerDialog.OnTimeSetListener timePickerDialogListener =
    new TimePickerDialog.OnTimeSetListener() {
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
         // put your code here
         // update your model/view given with the date selected by the user
        }
    };
// Get the current time
Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create Time Picker Dialog
TimePickerDialog timerPickerDialog = new TimePickerDialog(this,
  timePickerDialogListener, hour, minute, false);
// Display Time Picker Dialog
timerPickerDialog.show();

6 自定义对话框
权限
代码 Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.yourLayoutId);
dialog.show();

7 自定义提示对话框
权限
代码 LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.yourLayoutId, (ViewGroup) findViewById(R.id.yourLayoutRoot));
AlertDialog.Builder builder = new AlertDialog.Builder(this);
 .setView(layout);
AlertDialog alertDialog = builder.create();
alertDialog.show();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值