Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Date Picker Material Style

i have implemented the date picker on my fragment, this is the code:

edittext_from.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    final Calendar c = Calendar.getInstance();
                    mYear = c.get(Calendar.YEAR);
                    mMonth = c.get(Calendar.MONTH);
                    mDay = c.get(Calendar.DAY_OF_MONTH);
                    android.app.DatePickerDialog datePickerDialog = new android.app.DatePickerDialog(getContext(),
                            new android.app.DatePickerDialog.OnDateSetListener() {

                                @Override
                                public void onDateSet(DatePicker view, int year,
                                                      int monthOfYear, int dayOfMonth) {

                                    edittext_from.setText(String.format("%04d-%02d-%02d", year, (monthOfYear + 1), dayOfMonth));

                                }
                            }, mYear, mMonth, mDay);
                    datePickerDialog.show();
                }


            });

and the style of my date picker is a old style as this :DatePicker

I would like to use a DatePicker with material style, i have tried to use this library compile 'com.wdullaer:materialdatetimepicker:2.3.0', but the result is the same. Any help how i can change this DatePicker with Material Date Picker? Thanks

like image 463
APPGIS Avatar asked Feb 14 '17 11:02

APPGIS


People also ask

How do you use a fabric date picker?

mat-datepicker exampleAdd a template reference variable mat-datepicker element. Connect mat-datepicker to input element via [matDatepicker] property. Finally add date picker toggle button to display or hide calender popup by using mat-datepicker-toggle element.

How do I change my datepicker color MUI?

You can also create a custom theme and overwrite colors inside it: const theme = createTheme({ components: { MuiIconButton: { styleOverrides: { sizeMedium: { color } } }, MuiOutlinedInput: { styleOverrides: { root: { color } } }, MuiInputLabel: { styleOverrides: { root: { color } } } } });

What is the UI view controller that can be used to select a date and time for an Android mobile app?

Android Date Picker allows you to select the date consisting of day, month and year in your custom user interface. For this functionality android provides DatePicker and DatePickerDialog components.

What is date range picker?

The JavaScript Date Range Picker is a lightweight and mobile-friendly component that allows end users to select start and end date values as a range from a calendar pop-up or by entering values directly in the HTML input text box.


2 Answers

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());

enter image description here

like image 83
Gabriele Mariotti Avatar answered Oct 13 '22 01:10

Gabriele Mariotti


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:-

enter image description here

Hope this will help you thanks....

like image 26
Rahul Kushwaha Avatar answered Oct 13 '22 01:10

Rahul Kushwaha