android常用的四种对话框java代码

AlterDialog:确认取消警告提示框

public void showAlertDialog(View view){
    AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
    dialog.setTitle("这是一个AlertDialog");
    dialog.setMessage("对话框详细信息:请选择“取消”还是“确认”?");
    dialog.setCancelable(false);//不能取消    
    dialog.setPositiveButton("确认",new DialogInterface.OnClickListener(){
        @Override
        public void onClick(DialogInterface dialog,int which){
            TextView tv1 = (TextView)findViewById(R.id.textView);
            tv1.setText("你选择了确认!");
        }
    });
    dialog.setNegativeButton("取消", new DialogInterface.OnClickListener(){
        @Override
        public void onClick(DialogInterface dialog, int which){
          TextView tv1 = (TextView)findViewById(R.id.textView);
      }
    });
    dialog.show();
}

ProgressDialog进度条框:

public void showProgressDialog(View view){
    ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
    progressDialog.setTitle("这是一个进度条对话框");
    progressDialog.setMessage("请耐心等待,正在处理数据...");
    progressDialog.setCancelable(true);
    progressDialog.show();
}

DatePickerDialog日期选择框:

public void showDateDialog(View view){
    DatePickerDialog.OnDateSetListeneronDateSetListener= new DatePickerDialog.OnDateSetListener(){
        @Override
        public void onDateSet(DatePicker view, int year, int month, int dayOfMonth){
            TextView tv1 = (TextView)findViewById(R.id.textView);
            String theDate = String.format("你选择的日期:%d年%月%日", year, month, dayOfMonth);
            tv1.setText(theDate);
        }
    };
    DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, onDateSetListener, 2017, 5, 1);
    dataPickerDialog.show();
}    

TImePickerDialog 时间选择器:

public void showTimeDialog(View view){
    TimePickerDialog.OnTimeSetListeneronTimeSetListener = newTimePickerDialog.OnTimeSetListener(){
        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute){
            TextView tv1 = (TextView)findViewById(R.id.textView);
            String theTime = String.format("你选择的时间:%d:%d",hourOfDay, minute);
            tv1.setText(theTime);
        }
    };
    TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this, onTimeSetListener, 0,0,true);
    timePickerDialog.show();
}

 

上一篇:PYQT5点击菜单栏弹出新窗口,解决窗口闪退的问题


下一篇:Iup lua dialog size