Please try this
Field f[] = picker.getClass().getDeclaredFields();
for (Field field : f) {
if (field.getName().equals("mDayPicker")) {
field.setAccessible(true);
Object dayPicker = new Object();
dayPicker = field.get(picker);
((View) dayPicker).setVisibility(View.GONE);
}
}
}
catch (SecurityException e) {
Log.d("ERROR", e.getMessage());
}
catch (IllegalArgumentException e) {
Log.d("ERROR", e.getMessage());
}
catch (IllegalAccessException e) {
Log.d("ERROR", e.getMessage());
}
you can try this
DatePicker dpDate = (DatePicker) findViewById(R.id.dpDate);
// Initialize Date Picker
int year = dpDate.getYear();
int month = dpDate.getMonth();
int day = dpDate.getDayOfMonth();
dpDate.init(year, month, day, this);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
int daySpinnerId = Resources.getSystem().getIdentifier("day", "id", "android");
if (daySpinnerId != 0)
{
View daySpinner = dpDate.findViewById(daySpinnerId);
if (daySpinner != null)
{
daySpinner.setVisibility(View.GONE);
}
}
}
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
int monthSpinnerId = Resources.getSystem().getIdentifier("month", "id", "android");
if (monthSpinnerId != 0)
{
View monthSpinner = dpDate.findViewById(monthSpinnerId);
if (monthSpinner != null)
{
monthSpinner.setVisibility(View.GONE);
}
}
}
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
int yearSpinnerId = Resources.getSystem().getIdentifier("year", "id", "android");
if (yearSpinnerId != 0)
{
View yearSpinner = dpDate.findViewById(yearSpinnerId);
if (yearSpinner != null)
{
yearSpinner.setVisibility(View.GONE);
}
}
}
for More Information
Hide Day, Month, or Year from DatePicker in Android 5.0+ Lollipop