自定义对话框
//自定义对话框 public void bt_4(View v) { //1-Layout文件加载器 //LayoutInflater layoutInflater=getLayoutInflater(); // View view=layoutInflater.inflate(R.layout.zidingyiduihuakuang, null); //2-View的静态方法 //View view=View.inflate(this, R.layout.zidingyiduihuakuang, null); //3-java代码 ImageView view=new ImageView(this); view.setImageResource(R.drawable.nnn); new AlertDialog.Builder(this) //.setView(R.layout.zidingyiduihuakuang)版本5以上。 .setView(view) .show(); }
获取当前时间日期
//获取当前日期 //单例模式 Calendar c=Calendar.getInstance(); //c.get(Calendar.YEAR); //日期对话框 public void bt_6(View v) { DatePickerDialog dp=new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Toast.makeText(Text5Activity.this, year+"-"+monthOfYear+1+"-"+dayOfMonth, Toast.LENGTH_SHORT).show(); } }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)); dp.show();; } //时间对话框 public void bt_7(View v) { TimePickerDialog tp=new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { Toast.makeText(Text5Activity.this, hourOfDay+":"+minute, Toast.LENGTH_SHORT).show(); } }, c.get(Calendar.HOUR), c.get(Calendar.MINUTE), true); tp.setCanceledOnTouchOutside(false); tp.show();; }
时间对话框
//时间对话框 public void bt_7(View v) { TimePickerDialog tp=new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { Toast.makeText(Text5Activity.this, hourOfDay+":"+minute, Toast.LENGTH_SHORT).show(); } }, c.get(Calendar.HOUR), c.get(Calendar.MINUTE), true); tp.setCanceledOnTouchOutside(false); tp.show();; }
日期对话框
//日期对话框 public void bt_6(View v) { DatePickerDialog dp=new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Toast.makeText(Text5Activity.this, year+"-"+monthOfYear+1+"-"+dayOfMonth, Toast.LENGTH_SHORT).show(); } }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)); dp.show();; }
时间: 2024-10-12 00:27:18