当时找个很多的代码,都没有找到一个好的方法,这里直接上代码:
注意的是,,先把全部的时间显示出来再说:
大概写了两个,其他的大同小异:
private void hidDay(TimePicker timePicker2) {
Field[] datePickerfFields =timePicker2.getClass().getDeclaredFields();
for (Field datePickerField :datePickerfFields) {
if ("mMinuteSpinner".equals(datePickerField.getName())) {
//这里这个变量是系统的定义的变量,不是自己定义的,点击时间源码进去就可以看到很多定义的属性,这个就是分钟属性,控制这个就可以了
datePickerField.setAccessible(true);
ObjectdayPicker = new Object();
try{
dayPicker =datePickerField.get(timePicker2);
} catch(IllegalAccessException e) {
e.printStackTrace();
} catch(IllegalArgumentException e) {
e.printStackTrace();
}
//datePicker.getCalendarView().setVisibility(View.GONE);
((View)dayPicker).setVisibility(View.GONE);
}
}
}
private void hidDay(DatePicker mDatePicker){
Field[]datePickerfFields =mDatePicker.getClass().getDeclaredFields();
for (FielddatePickerField : datePickerfFields) {
if ("mDaySpinner".equals(datePickerField.getName())) {
//这里这个变量是系统的定义的变量,不是自己定义的
datePickerField.setAccessible(true);
Object dayPicker = new Object();
try {
dayPicker =datePickerField.get(mDatePicker);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
//datePicker.getCalendarView().setVisibility(View.GONE);
((View)dayPicker).setVisibility(View.GONE);
}
}
}