public void shuip(View view) {
//1.实例化对象
final ProgressDialog dialog = new ProgressDialog(this);
//设置属性
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);//水平进度条
// dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//转圈进度条
dialog.setMax(100);//最大值
dialog.setProgress(0);//当前值
dialog.setMessage("正在下载");
dialog.show();
//模拟定时器
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
int n = 0;
@Override
public void run() {
if (n == 100){
dialog.dismiss();//消失
timer.cancel();
}
dialog.setProgress(n+=10);
}
},0,1000);
}
日期选择对话框
public void date(View view) {
Calendar instance = Calendar.getInstance();
new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
Toast.makeText(MainActivity.this, year+"-"+(month+1)+"-"+dayOfMonth, Toast.LENGTH_SHORT).show();
}
},instance.get(Calendar.YEAR),instance.get(Calendar.MONTH),instance.get(Calendar.DAY_OF_MONTH)).show();
}
时间选择对话框
public void Timew(){
Calendar calendar=Calendar.getInstance();//日历对象
//TODO 1:实例化对象 TODO 2:show
new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
Toast.makeText(MainActivity.this, hourOfDay+":"+minute, Toast.LENGTH_SHORT).show();
}
},calendar.get(Calendar.HOUR),calendar.get(Calendar.MINUTE),true).show();
}