Search code examples
androidandroid-datepicker

DatePickerDialog Issue in Android


I am unable to see the initials of Day in DatePickerDialog

enter image description here

What I want is :

enter image description here

The code I am using for showing dialog is :

 DatePickerDialog dialog = new DatePickerDialog(context, startingDateSetListener,
                    starting_date_object.getYear(),
                    starting_date_object.getMonthOfYear()-1,
                    starting_date_object.getDayOfMonth());

            dialog.getDatePicker().setMaxDate(ending_date_object.getMillis());
            dialog.show();

Solution

  • The days are probably there but their textColor is the same as the background so you can't see them. This has to do with the style/theme of the dialog.
    Create a theme in styles.xml like:

    <style name="DatePickerTheme" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorAccent">@color/your_accent_color</item>
        <item name="colorControlActivated">@color/your_control_activated_color</item>
    </style>
    

    and initialize the DatePickerDialog by supplying the theme:

     DatePickerDialog dialog = new DatePickerDialog(context,
                        R.style.DatePickerTheme, 
                        startingDateSetListener,
                        starting_date_object.getYear(),
                        starting_date_object.getMonthOfYear()-1,
                        starting_date_object.getDayOfMonth());