calendarViewShown在Android 5.0棒棒糖上没有被尊重

我正在通过大书呆子牧场的Android指南。 在犯罪意图分配我使用DatePicker与以下布局。

在5.0以前版本的设备上,日历不会在布局中定义的DatePicker中显示,但Android 5.0会忽略此信息并显示日历。 任何想法可能会发生在这里?

完整的代码在Github上可用。

dialog_date.xml

<?xml version="1.0" encoding="utf-8"?> <DatePicker xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/dialog_date_datePicker" android:layout_width="match_parent" android:layout_height="match_parent" android:calendarViewShown="false" > </DatePicker> 

DatePickerFragment.java

 package com.sudhirkhanger.android.criminalintent; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.view.View; import android.widget.DatePicker; import android.widget.DatePicker.OnDateChangedListener; public class DatePickerFragment extends DialogFragment { public static final String EXTRA_DATE = "com.sudhirkhanger.android.criminalintent.date"; private Date mDate; public static DatePickerFragment newInstance(Date date) { Bundle args = new Bundle(); args.putSerializable(EXTRA_DATE, date); DatePickerFragment fragment = new DatePickerFragment(); fragment.setArguments(args); return fragment; } private void sendResult(int resultCode) { if (getTargetFragment() == null) return; Intent i = new Intent(); i.putExtra(EXTRA_DATE, mDate); getTargetFragment().onActivityResult(getTargetRequestCode(), resultCode, i); } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { mDate = (Date) getArguments().getSerializable(EXTRA_DATE); // Create a Calendar to get the year, month, and day final Calendar calendar = Calendar.getInstance(); // calendar.setTime(mDate); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int day = calendar.get(Calendar.DAY_OF_MONTH); View v = getActivity().getLayoutInflater().inflate( R.layout.dialog_date, null); DatePicker datePicker = (DatePicker) v .findViewById(R.id.dialog_date_datePicker); datePicker.init(year, month, day, new OnDateChangedListener() { public void onDateChanged(DatePicker view, int year, int month, int day) { // Translate year, month, day into a Date object using a // calendar int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); mDate = new GregorianCalendar(year, month, day, hour, minute) .getTime(); // Update argument to preserve selected value on rotation getArguments().putSerializable(EXTRA_DATE, mDate); } }); return new AlertDialog.Builder(getActivity()) .setView(v) .setTitle(R.string.date_picker_title) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { sendResult(Activity.RESULT_OK); } }).create(); } } 

Solutions Collecting From Web of "calendarViewShown在Android 5.0棒棒糖上没有被尊重"

解决scheme已发布在这里

你必须同时使用android:calendarViewShown="false"android:datePickerMode="spinner"

这解决了它。

 <DatePicker xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/dialog_date_datePicker" android:layout_width="match_parent" android:layout_height="match_parent" android:calendarViewShown="false" android:datePickerMode="spinner" > </DatePicker> 

下面的代码为我工作

 new DatePickerDialog(getActivity(),android.R.style.Theme_Holo_Dialog, this, year,month, day);