Reputation: 1243
I've implemented MaterialDatePicker for the purpose of the date selection & also done it but in calendar header initially shows the First date of the current month
Example: Today date is May 30 2020 but in the calendar before select any date i.e initially it shows May 1 2020.
Here is the code & screenshot:
MaterialDatePicker.Builder startDateBuilder;
MaterialDatePicker startDatePicker;
startDateBuilder = MaterialDatePicker.Builder.datePicker();
startDateBuilder.setTitleText("Starting date");
long today = MaterialDatePicker.todayInUtcMilliseconds();
CalendarConstraints.Builder con = new CalendarConstraints.Builder();
CalendarConstraints.DateValidator dateValidator = DateValidatorPointForward.now();
con.setValidator(dateValidator); // Previous dates hide
con.setStart(today); // Calender start from set day of the month
startDateBuilder.setSelection(today);
startDateBuilder.setCalendarConstraints(con.build());
startDateBuilder.setTheme(R.style.MaterialCalendarTheme); // Custom Theme
startDatePicker = startDateBuilder.build();
startDatePicker.show(getSupportFragmentManager(), startDatePicker.toString());
Upvotes: 2
Views: 1281
Reputation: 1243
My code is correct it was dependencies version problem. Previously I used the old version, Now update the new version, it was working fine.
com.google.android.material:material:1.2.0-alpha02
after changing the implementation
com.google.android.material:material:1.2.0-beta01
In beta01 also have some bugs in shows the current date in the header of the calendar and also a picker.
It doesn't show the current date in beta01 version so I changed to the stable version Now it will work.
com.google.android.material:material:1.1.0
Upvotes: 1