Search code examples
androidkotlinandroid-activitydatepickerdatetimepicker

Android Date Picker showing unwanted view


val datePickerDialog = DatePickerDialog(
                        this@AddTaskActivity,
                        R.style.DateTimePickerTheme,
                        startDatePickerListener,
                        myCalendar
                                .get(Calendar.YEAR),
                        myCalendar.get(Calendar.MONTH),
                        myCalendar.get(Calendar.DAY_OF_MONTH)
                )
    <style name="DateTimePickerTheme" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/theme_blue</item>
    </style>

above is my code , view showing as above image 1. but expected as below image 2. there is Unwanted date is top of the date picker

Image 1 (Showing) Image 1

Image 2 (Expected Image) Image 2


Solution

  • You have to remove title bar. To Remove title bar.. use this code

    datePickerDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    

    And Don't call datePickerDialog.setTitle("title")

    Remove setTitle if you use

    datePickerDialog.setTitle("title")