Remove Title from DatePickerDialog

2019-01-18 11:44发布

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();

5条回答
▲ chillily
2楼-- · 2019-01-18 11:48
datePickerDialog.setTitle("");
查看更多
成全新的幸福
3楼-- · 2019-01-18 11:53
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

查看更多
干净又极端
4楼-- · 2019-01-18 12:09

More appropriate so that it even supports holo versions

    datePickerDialog.setCustomTitle(null);
查看更多
啃猪蹄的小仙女
5楼-- · 2019-01-18 12:12

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);
查看更多
冷血范
6楼-- · 2019-01-18 12:14

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.

查看更多
登录 后发表回答