Impossible to make my DatePickerDialog use a spinner style programmatically

Related searches

I'm using a DialogFragment to open a DatePickerDialog

public class DatePickerFragment extends DialogFragment{

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    // Use the current date as the default date in the picker
    final Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);


    // Create a new instance of DatePickerDialog and return it
    DatePickerDialog DatePickerDialog = new DatePickerDialog(getActivity(), (ProfileCreationActivity)getActivity(), year, month, day);
    return DatePickerDialog;
}

I'm getting a calendar look, where I would prefer a spinner look.

I tried:

datePickerDialog.getDatePicker().setCalendarViewShown(false);

and

datePickerDialog.getDatePicker().setLayoutMode(1);

but it does not work.

Please note that I want the spinner look for one activity, but that I will want the calendar view for another activity. So I can not change the whole application style. I need a custom style for one activity.

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.

How to set datePickerMode="spinner" programmatically?, Impossible to make my DatePickerDialog use a spinner style programmatically. Question. I'm using a DialogFragment to open a DatePickerDialog public class� Impossible to make my DatePickerDialog use a spinner style programmatically. 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

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

<style name="AppTheme"  parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="colorControlActivated">@color/colorPrimary</item>
    <item name="android:timePickerDialogTheme">@style/PickerDialogCustom</item>
    <item name="android:datePickerDialogTheme">@style/PickerDialogCustom</item>
    <item name="alertDialogTheme">@style/AlertDialogCustom</item>
</style>

<style name="PickerDialogCustom" parent="AlertDialogCustom">
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:textColorPrimary">@color/colorPrimaryDark</item>
    <item name="colorControlNormal">@color/greyLight500</item>
    <item name="android:layout_margin">2dp</item>
    <item name="android:datePickerMode">spinner</item>
</style>

<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorAccent">@color/colorPrimary</item>
    <item name="android:positiveButtonText">@color/colorPrimary</item>
    <item name="android:negativeButtonText">@color/greyDark200</item>
    <item name="buttonBarNegativeButtonStyle">@style/negativeButton</item>
    <item name="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);

How to set datePickerMode=“spinner” programmatically?, FROM: Impossible to make my DatePickerDialog use a spinner style programmatically. Hope it help. Is there a way to use the spinner version of the� Impossible to make my DatePickerDialog use a spinner style programmatically. 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

<item name="android:datePickerMode">spinner</item>Just add one line in style v21

How to change the style of a DatePicker in android?, FROM: Impossible to make my DatePickerDialog use a spinner style If you want to set it programmatically you can you the below code but I haven't checked � If you want to use a Spinner instead of calendar or clock in DatePickerDialog or TimePickerDialog, you can do as following. READ : How To Download APK From Google Play Online Just use a build-in style or customized theme style when create the DatePickerDialog or TimePickerDialog instance.

android, Light is not a dialog Just set certain text color in your date picker dialog style. Or maybe if that's not possible, somehow create a Style programmatically with my I made a How to Make DatePicker Only Show Spinner Using Java, datePicker. How to design custom datepickerdialog in android application to get date from user. Date picker dialog is used to get date form user into android application. DatePickerDialog is a custom pop up date selection box . So here is the complete step by step tutorial for Create DatePickerDialog in android example with DialogFragment.

i need create datepicker programmatically. , can't use xml layout. know set the solution create dedicated custom dialog xml layout file using requested attribute. from: impossible make datepickerdialog use spinner style� To use DatePickerDialog, first you need to create a dialog fragment by extending DialogFragment and implementing onCreateDialog method which returns DatePickerDialog instance. In the implementation of onCreateDialog method of date picker fragment, instantiate DatePickerDialog by setting current date and return it.

There are so many examples to convert this calendar view into spinner mode. But some of them are quite hard to understand or some of them has huge process to achieve. Here you will find the smartest and fastest way to do it. You can change style into Holo Dark Dialog Theme. see below screenshot.

Comments
  • What you have should work. Things that make you go hmmmm....
  • This answer worked for me with just one line.
  • Would it be okay if you can give a sample of negativeButton style resource to work with?