Android Date Picker Material Style
With the Material Components for Android you can use the new MaterialDatePicker
.
Currently it is under active development and requires version 1.1.0 of material components for android library.
implementation 'com.google.android.material:material:1.1.0'
Just use:
MaterialDatePicker.Builder<Long> builder = MaterialDatePicker.Builder.datePicker();
builder.setTitleText(R.string.your_text);
MaterialDatePicker<Long> picker = builder.build();
picker.show(getSupportFragmentManager(), picker.toString());
Try this : Material DatePicker By Arsenal
If any doubt see my github Repository
GitHUb:-https://github.com/rahulkushwaha482/DatePickerDialogFragment
First add this dependencies
implementation('com.shagi:material-datepicker:1.3') {
exclude group: 'com.android.support'
}
Add permission for Internet
This is required by this project.
1)In kotlin ,use this code:-
val dialog = DatePickerFragmentDialog.newInstance({ view, year, monthOfYear, dayOfMonth ->
Toast.makeText(applicationContext,
"year $year month $monthOfYear day $dayOfMonth",
Toast.LENGTH_SHORT).show()
}, 2017, 11, 4)
dialog.show(supportFragmentManager, "tag")
/* Possible params
dialog.setMaxDate(System.currentTimeMillis())
dialog.setMinDate(System.currentTimeMillis())
dialog.setYearRange(2000, 2010)
dialog.setCancelColor(Color.MAGENTA)
dialog.setOkColor(Color.MAGENTA)
dialog.setAccentColor(Color.MAGENTA)
dialog.setCancelText("Out")
dialog.setOkText("Fine")
*/
2)In Java , use this code:-
DatePickerFragmentDialog datePickerFragmentDialog=DatePickerFragmentDialog.newInstance(new DatePickerFragmentDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePickerFragmentDialog view, int year, int monthOfYear, int dayOfMonth) {
txtTodayDate.setText(dayOfMonth + "/" + (monthOfYear + 1) + "/" + year);
}
},mYear, mMonth, mDay);
datePickerFragmentDialog.show(getSupportFragmentManager(),null);
datePickerFragmentDialog.setMaxDate(System.currentTimeMillis());
datePickerFragmentDialog.setYearRange(1900,mYear);
datePickerFragmentDialog.setCancelColor(getResources().getColor(R.color.colorPrimaryDark));
datePickerFragmentDialog.setOkColor(getResources().getColor(R.color.colorPrimary));
datePickerFragmentDialog.setAccentColor(getResources().getColor(R.color.colorAccent));
datePickerFragmentDialog.setOkText(getResources().getString(R.string.ok_dob));
datePickerFragmentDialog.setCancelText(getResources().getString(R.string.cancel_dob));
Your result will look like this:-
Hope this will help you thanks....