如何禁用DatePickerDialog的标题?

时间:2016-06-21 10:27:34

标签: android android-layout android-dialog android-datepicker

void showDatePickerDailog() {
    Calendar cal = Calendar.getInstance(TimeZone.getDefault());
    DatePickerDialog datePicker = new DatePickerDialog(mContext, datePickerListener,
        cal.get(Calendar.YEAR),
        cal.get(Calendar.MONTH),
        cal.get(Calendar.DAY_OF_MONTH));
    datePicker.setCancelable(false);
    ((ViewGroup) datePicker.getDatePicker()).findViewById(Resources.getSystem().getIdentifier("day", "id", "android")).setVisibility(View.GONE);
    long timeadj = 24*60*60*1000;
    datePicker.getDatePicker().setMinDate((new Date().getTime())+timeadj);
    datePicker.show();
}

我尝试了上面的代码,但它崩溃了。如何禁用datepicker标题?

2 个答案:

答案 0 :(得分:0)

删除对话框标题在dialog.show()之前添加以下代码段。

datePicker.requestWindowFeature(Window.FEATURE_NO_TITLE);

答案 1 :(得分:-1)

AlertDialog使用setCustomHeader方法,使用它并设置宽度为zerozero的自定义视图。它会起作用

LinearLayout linearLayout = new LinearLayout(getApplicationContext());
timePickerDialog.setCustomTitle(linearLayout);