Android Material Design Inline Datepicker Issue

Android Material Design Inline Datepicker issue

The calendarViewShown attribute is deprecated in the calendar-style date picker. If you want the spinner-style date picker back, you can set the datePickerMode attribute to spinner.

<DatePicker
...
android:datePickerMode="spinner" />

As for the scrolling issue, the calendar-style date picker doesn't support nested scrolling.

inline datepicker in android

Just use the getYear(), getMonth() and getDayOfMonth() methods:

DatePicker datePicker = (DatePicker) findViewById(R.id.my_date);    

int year = datePicker.getYear();
int month = datePicker.getMonth();
int day = datePicker.getDayOfMonth();

DatePicker in a DialogFragment ignores setCalendarViewShown

In my "values-v21/styles.xml" I've modified activity theme as below it's hiding calendar & shows simple datepicker spinner. You might want to use a drawable with white background & rounded corners:

    <item name="android:datePickerDialogTheme">@style/style_date_picker_dialog</item>
</style>

<style name="style_date_picker_dialog" parent="@android:style/Theme.DeviceDefault.Light">
<item name="android:windowIsFloating">true</item>
<item name="android:windowBackground">@drawable/dialog_background</item>
<item name="android:datePickerStyle">@style/style_datepicker</item>
</style>

<style name="style_datepicker" parent="android:Widget.Material.Light.DatePicker">
<item name="android:datePickerMode">spinner</item>
</style>

Validation 18 years old in DatePicker

If you want 18 years ago in epoch milliseconds to set as the max/starting date of your picker, you can use:

(ZonedDateTime.now() - Period.ofYears(18)).toInstant().toEpochMilli()

Or if you want to validate, you can compare like this:

val eighteenYearsAgo = LocalDate.now() - Period.ofYears(18)

val listener = DatePickerDialog.OnDateSetListener { _, year, month, day ->
// +1 month because DatePicker's month is unfortunately zero-based
val pickedDate = LocalDate.of(year, month + 1, day)
if (pickedDate < eighteenYearsAgo) {
// Picked a date less than 18 years ago
}
}

I cant be able to set datepicker starts from tomorrows date(Material Design Datepicker)

Try this out!

dateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar now = Calendar.getInstance();
now.add(Calendar.DAY_OF_YEAR, 1);
DatePickerDialog dpd = DatePickerDialog.newInstance(
MainActivity.this,
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH)
);
dpd.setMinDate(now);
dpd.setThemeDark(modeDarkDate.isChecked());
dpd.vibrate(vibrateDate.isChecked());
dpd.dismissOnPause(dismissDate.isChecked());
dpd.showYearPickerFirst(showYearFirst.isChecked());
if (modeCustomAccentDate.isChecked()) {
dpd.setAccentColor(Color.parseColor("#9C27B0"));
}
if(titleDate.isChecked()) {
dpd.setTitle("DatePicker Title");
}
dpd.show(getFragmentManager(), "Datepickerdialog");
}
});
}

DatePicker custom Numberpicker Style not working after change

After done a lot of research i've seen that you cant do that selection style on android 4.1.X like you could do on previous versions. What you can do is to create a class that extends NumberPicker and add this code:

if (child instanceof EditText) {
((EditText) child).setTextSize(35);
}

but still you are not able to use a different style for selected numbers, so what i did is to use simonVT numberpicker (https://github.com/SimonVT/android-numberpicker) wich after some customization solved the problem.



Related Topics



Leave a reply



Submit