'Remove Title from DatePickerDialog
For some reason, I have two titles in my DatePickerDialog.
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();
Solution 1:[1]
datePickerDialog.setTitle("");
Solution 2:[2]
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.
Solution 3:[3]
More appropriate so that it even supports holo versions
datePickerDialog.setCustomTitle(null);
Solution 4:[4]
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
Solution 5:[5]
Use this to also hide the title background
datePickerDialog.setTitle(null);
Solution 6:[6]
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>
Solution 7:[7]
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);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Shrey |
Solution 2 | |
Solution 3 | Sheychan |
Solution 4 | Pankaj Talaviya |
Solution 5 | Amir Dora. |
Solution 6 | Kirguduck |
Solution 7 | cuasodayleo |