0

I'm using DataPicker to implement Data Dialog: import android.widget.DatePicker;

When I tested on API < 21 there is no problem:

enter image description here

But on API > 21 there is problem (I think because of material design) dialog looks:

enter image description here

And sometimes there are scaled buttons, corners etc. I would like to have identical design for both cases.

How to force not to use the android material design in this case ?

Method:

public Dialog ShowDate(final Context context, String title,
            OnClickListener listener, int year, int mounth, int day) {

        Dialog dialog = new Dialog(context);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View mView = inflater.inflate(R.layout.date_picker, null);
        DatePicker date = (DatePicker) mView.findViewById(R.id.date);
        TextView titleDate = (TextView) mView.findViewById(R.id.titleDate);
        titleDate.setText(title);
        Button cancel = (Button) mView.findViewById(R.id.cancelDate);
        Button ok = (Button) mView.findViewById(R.id.okDate);
        cancel.setOnClickListener(listener);
        ok.setOnClickListener(listener);
        if (year == 0) {
            date.updateDate(1990, 4, 9);
        } else {
            date.updateDate(year, mounth - 1, day);
        }

        dialog.setContentView(mView);

        dialog.show();
        return dialog;
    }
VLeonovs
  • 2,193
  • 5
  • 24
  • 44

2 Answers2

2

Try this DatePicker_datePickerMode = spinner in your style.xml See:https://developer.android.com/reference/android/R.styleable.html#DatePicker_datePickerMode

Jing
  • 1,090
  • 9
  • 13
1

You have two options:

Manually specify the desired theme and style for the DatePicker. Check this out: Specify theme and style for DatePicker

Or you can set it to the spinner mode in the xml file as @Jing proposed.

android:datePickerMode="spinner"
Community
  • 1
  • 1
Aksiom
  • 1,565
  • 4
  • 25
  • 39