My sample code below In OnCreateDialog event calling method below
SetNumericMonth(true, null, dialog);
private int monthSpinnerResId;
public void SetNumericMonth(bool onCreateEventOrNot, DatePicker view, DatePickerDialog dialog)
{
if (DatePickerNumericMonthFormat == false)
{
monthSpinnerResId = Activity.Resources.GetIdentifier("android:id/month", null, null);
if (monthSpinnerResId != 0)
{
var numberPicker = (NumberPicker)dialog.DatePicker.FindViewById<NumberPicker>(monthSpinnerResId);
numberPicker.SetFormatter(new NumericMonthFormatter());
numberPicker.MinValue = 0;
numberPicker.MaxValue = 9;
}
}
}
public class NumericMonthFormatter: Java.Lang.Object, NumberPicker.IFormatter
{
public string Format1(int value)
{
return string.Format("{0:D2}", value);
}
}
You can try to create your DatePickerDialog and set the month number picker's display values. Such as:
And in the main activity:
And there are some point for your code:
In the styles.xml:
If the default style is calendar, the
var numberPicker = (NumberPicker)dialog.DatePicker.FindViewById<NumberPicker>(monthSpinnerResId);will get null.In addition, if just use the formatter, the display values will be reset when the date changed. So I try to use the custom datepicker dialog.