Mehvish Ali
Mehvish Ali

Reputation: 752

DatePickerDialog not working as expected

I have an EditView in which I am trying to bind DatePickerDialog. Its working well with the api 19. but when tested on api version 25 Marshmallow the calendar becomes white and when selected some date the EditView is not populated as well i.e I am unable to set date in Marshmallow.

Code:

warrantyExpEt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new DatePickerDialog(getContext(), date, myCalendar
                        .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
                        myCalendar.get(Calendar.DAY_OF_MONTH)).show();
            }
        });


    final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear,
                                  int dayOfMonth) {
                // TODO Auto-generated method stub
                myCalendar.set(Calendar.YEAR, year);
                myCalendar.set(Calendar.MONTH, monthOfYear);
                myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                updateLabel();
            }

        };
        private void updateLabel() {

            String myFormat = "yyyy-MM-dd";
            SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);

            warrantyExpEt.setText(sdf.format(myCalendar.getTime()));
        }

Upvotes: 1

Views: 1501

Answers (3)

Minkoo
Minkoo

Reputation: 439

Remove this from your style:

<item name="android:textColorPrimary">@color/white</item>

Upvotes: 1

Dileep Patel
Dileep Patel

Reputation: 1988

try to this it can show dialog as you want

   new DatePickerDialog(MainActivity.this, R.style.datepicker, new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int month, int day) {

            calendar.set(Calendar.YEAR, year);
            calendar.set(Calendar.MONTH, month);
            calendar.set(Calendar.DAY_OF_MONTH, day);

        }
    }, year, month, day).show();

dialog style as you wish

  <style name="datepicker" parent="Theme.AppCompat.Light.Dialog">

    <item name="colorAccent">@color/red</item>
</style>

Upvotes: 0

Rahul Sharma
Rahul Sharma

Reputation: 13593

this might be the Theme you are using in your project. So use below theme in your style file

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
   <item name="colorPrimary">@color/green_sheet</item>
   <item name="android:textAllCaps">false</item>     
</style>

Hope this will help you out.

Upvotes: 1

Related Questions