对话框类型
普通对话框
进度条对话框
单选对话框
one.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setIcon(R.mipmap.ic_launcher);
builder.setTitle("提示方式");
final String s[]=new String[]{"1","2"};
builder
.setSingleChoiceItems(s, 0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "111", Toast.LENGTH_SHORT).show();
}
}).setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "成功", Toast.LENGTH_SHORT).show();
}
}).create().show();
}
});
多选对话框
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setIcon(R.mipmap.ic_launcher);
builder.setTitle("提示方式");
final String s[]=new String[]{"1","2"};
final boolean[] b=new boolean[]{true,false};
builder
.setMultiChoiceItems(s, b, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
}
}).create().show();
时间对话框
Date date = new Date();
int hour=date.getHours();
int mm=date.getSeconds();
TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
}
},hour,mm,true);
timePickerDialog.show();
日期对话框
Calendar calendar = Calendar.getInstance();
int year=calendar.get(Calendar.YEAR);
int mouth=calendar.get(Calendar.MONTH);
int day=calendar.get(Calendar.DATE);
DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
}
},year,mouth,day);
datePickerDialog.show();
自定义对话框
自定义对框框需要创建一个小布局放入自定义的对话类让其显示然后对其进行自定义化