Impossible To Make My Datepickerdialog Use A Spinner Style Programmatically
Solution 1:
I have found a the explanation in the following post (which describes a problem very similar to mine) :
Android Material Design Inline Datepicker issue
In fact the setCalendarViewShown(false) and setSpinnersShown(true) are apparently not working anymore in latest versions.
We have to use an explicit XML attribute like this one android:datePickerMode="spinner".
The problem is that I'm using a DialogFragment without any XML layout (just a date picker dialog). So I cannot set any XML attribute.
The solution is to create a dedicated custom dialog with an XML layout file using the requested attribute.
Solution 2:
You can keep it programatically, don't need to create a new XML with the spinner, I simply changed my AppTheme(v21) style and worked ;-)
<stylename="AppTheme"parent="Theme.AppCompat.Light.NoActionBar"><itemname="colorPrimary">@color/colorPrimary</item><itemname="colorPrimaryDark">@color/colorPrimaryDark</item><itemname="colorAccent">@color/colorAccent</item><itemname="colorControlActivated">@color/colorPrimary</item><itemname="android:timePickerDialogTheme">@style/PickerDialogCustom</item><itemname="android:datePickerDialogTheme">@style/PickerDialogCustom</item><itemname="alertDialogTheme">@style/AlertDialogCustom</item></style><stylename="PickerDialogCustom"parent="AlertDialogCustom"><itemname="android:textColor">@color/colorPrimary</item><itemname="android:textColorPrimary">@color/colorPrimaryDark</item><itemname="colorControlNormal">@color/greyLight500</item><itemname="android:layout_margin">2dp</item><itemname="android:datePickerMode">spinner</item></style><stylename="AlertDialogCustom"parent="Theme.AppCompat.Light.Dialog.Alert"><itemname="colorPrimary">@color/colorPrimary</item><itemname="colorAccent">@color/colorPrimary</item><itemname="android:positiveButtonText">@color/colorPrimary</item><itemname="android:negativeButtonText">@color/greyDark200</item><itemname="buttonBarNegativeButtonStyle">@style/negativeButton</item><itemname="android:datePickerStyle">@style/PickerDialogCustom</item></style>
remember to keep the support for <21 just adding this line, this command is ignored for >=21
datePickerDialog.getDatePicker().setLayoutMode(1);
Solution 3:
<item name="android:datePickerMode">spinner</item>
Just add one line in style v21
Solution 4:
Give it a theme.
DatePickerDialog dpd = new DatePickerDialog(.this,
android.R.style.Theme_Holo_Light_Dialog_NoActionBar, expirationDatePickerDialog,
myCalendar.get(Calendar.YEAR),
myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH));
Post a Comment for "Impossible To Make My Datepickerdialog Use A Spinner Style Programmatically"