I use the code below to hide the Date in Date picker. This code is great for Android Marshmallow, Lollipop. But it crashes when I try to use it on an Android Nougat device.
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;
}
An accident is found in the following code.
((ViewGroup) myDatePickerDialog.getDatePicker())
.findViewById(Resources.getSystem().getIdentifier("day", "id",
"android")).setVisibility(View.GONE);
source
share