我使用以下代码隐藏日期选择器中的日期。此代码适用于Android Marshmallow,Lollipop版本。但是当我在Android Nougat设备中尝试它时崩溃了。
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
MyDatePickerDialog myDatePickerDialog = new MyDatePickerDialog(this, android.R.style.Theme_Holo_Light_Dialog, onDateSetListener, y, m, d);
myDatePickerDialog.setPermanentTitle("Date Picker");
((ViewGroup) myDatePickerDialog.getDatePicker())
.findViewById(
Resources.getSystem().getIdentifier("day", "id",
"android")).setVisibility(View.GONE);
DatePicker datePicker = myDatePickerDialog.getDatePicker();
datePicker.setCalendarViewShown(false);
datePicker.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);
return myDatePickerDialog;
}
崩溃可在以下代码中找到。
((ViewGroup) myDatePickerDialog.getDatePicker())
.findViewById(Resources.getSystem().getIdentifier("day", "id",
"android")).setVisibility(View.GONE);