/**
* @description 选择日期弹出框
* @param listener 选择日期确定后执行的接口
* curDate 当前显示的日期
* @return
* @author wqy
* @time 2020-1-6 14:23
*/
public void showDatePickDialog(DatePickerDialog.OnDateSetListener listener,String curDate) {
Calendar calendar = Calendar.getInstance();
int year = 0,month = 0,day = 0;
try {
year =Integer.parseInt(curDate.substring(0,curDate.indexOf("-"))) ;
month =Integer.parseInt(curDate.substring(curDate.indexOf("-")+1,curDate.lastIndexOf("-")))-1 ;
day =Integer.parseInt(curDate.substring(curDate.lastIndexOf("-")+1,curDate.length())) ;
} catch (Exception e) {
e.printStackTrace();
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
day=calendar.get(Calendar.DAY_OF_MONTH);
}
DatePickerDialog datePickerDialog = new DatePickerDialog(this>调用
showDatePickDialog(new DatePickerDialog.OnDateSetListener() {
@Override
void onDateSet(DatePicker datePicker,int year,1)">int month,1)">int day) {
etDate.setText(year + "-" + (month + 1) + "-" + day);
}
},etDate.getText().toString());
@Override
boolean onTouch(View view,MotionEvent motionEvent) {
if (motionEvent.getAction()==MotionEvent.ACTION_DOWN){
hideInput();//隐藏输入框
switch (view.getId()) {
case R.id.etDate:
showDatePickDialog( DatePickerDialog.OnDateSetListener() {
@Override
day) {
选择日期过后执行的事件
etDate.setText(year + "-" + (month + 1) + "-" + day);
}
},etDate.getText().toString());
break;
}
}
return false;
}
* 隐藏键盘
protected hideInput() {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
View v = getWindow().peekDecorView();
if (null != v) {
imm.hideSoftInputFromWindow(v.getWindowToken(),0);
}
}