19

For some reason, I have two titles in my DatePickerDialog.

[Screenshot](http://i.imgur.com/8rVEjlv.png)

How can I get rid of the white title at the top? This is the code I use to create the Dialog:

datePickerDialog = new DatePickerDialog(ProfileActivity.this, this, year, month, day);
datePickerDialog.getDatePicker().updateDate(year, month - 1, day);
datePickerDialog.show();
EGHM
  • 2,144
  • 23
  • 37
Alex
  • 402
  • 5
  • 13

7 Answers7

35
datePickerDialog.setTitle("");
Shrey
  • 671
  • 7
  • 14
16

I found that for myself: datePickerDialog.getDatePicker().setMaxDate(c.getTimeInMillis());

and probably for you: datePickerDialog.getDatePicker().updateDate(year, month - 1, day);

is the culprit. If you leave that line out, you won't have a title.

I'm looking into setting a specific theme tosolve the issue.

-- UPDATE --

Make sure you call .setTitle(""); AFTER you call .getDatePicker().x(). Otherwise it will not work.

Spoetnic
  • 594
  • 7
  • 10
0

More appropriate so that it even supports holo versions

    datePickerDialog.setCustomTitle(null);
Sheychan
  • 2,415
  • 14
  • 32
0
datePickerDialog = new DatePickerDialog(ProfileActivity.this, this, year, month, day);
datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis());
datePickerDialog.setTitle("");
datePickerDialog.show();

your should add datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis()); and then add datePickerDialog.setTitle("");

this type of sequence to remove top white background header

Pankaj Talaviya
  • 3,328
  • 28
  • 31
0

Use this to also hide the title background

datePickerDialog.setTitle(null);
Amir Dora.
  • 2,831
  • 4
  • 40
  • 61
Shayan Samad
  • 294
  • 1
  • 10
0

apply it in your styles

 <style name="MaterialCalendarTheme" parent="ThemeOverlay.MaterialComponents.MaterialCalendar">
    <item name="materialCalendarHeaderTitle">@style/HeaderTitle_Hide</item>
</style>

<style name="HeaderTitle_Hide" parent="@style/Widget.MaterialComponents.MaterialCalendar.HeaderTitle">
    <item name="android:visibility">gone</item>
</style>
Kirguduck
  • 748
  • 1
  • 9
  • 20
-1

AlertDialog have setCustomHeader method, using it and set a custom view with zero width, zero height. It will work

LinearLayout linearLayout = new LinearLayout(getApplicationContext());
timePickerDialog.setCustomTitle(linearLayout);
cuasodayleo
  • 466
  • 5
  • 16