0

I want to use spinner mode for timepicker control in .net maui but when use this control show clock mode in my app please help me to change mode of timepicker Currently displaying this model

Customize Android TimePicker to use Spinner in .net Maui i use this solution but it is not work and i think it is not correctly solution.

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 20 '23 at 12:41

1 Answers1

0

According to this case about the TimePickerDialog in spinner mode in the native android, you can pass the deprecated Theme_Holo_Light_Dialog_NoActionBar theme to the TimePickerDialog's constructor.

And you can use the custom handler to do that. At first, please create the Custom Handler class in the /Platforms/Android:

public class MyTimePickerHandler : TimePickerHandler
    {
        protected override TimePickerDialog CreateTimePickerDialog(int hour, int minute)
        {
            TimePickerDialog timePickerDialog =  new(
                              this.Context,
                         global::Android.Resource.Style.ThemeHoloLightDialogNoActionBar,
                         (s, e) => {
                                    this.VirtualView.Time = new TimeOnly(e.HourOfDay, e.Minute,0).ToTimeSpan();
                                    DateTime dateTime = DateTime.Today.Add(this.VirtualView.Time);
                                    this.PlatformView.Text = dateTime.ToString("h:mm tt"); ;
                              },
                              this.VirtualView.Time.Hours,
                              this.VirtualView.Time.Minutes,
                              false);
           
            return timePickerDialog;
        }
    }

And then use the custom handler in the mauiprogram.cs:

builder
                  .UseMauiApp<App>()
                  .ConfigureFonts(fonts =>
                  {
                        fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                        fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
                  })
                  .ConfigureMauiHandlers(handlers =>
                  {
#if ANDROID
                        handlers.AddHandler(typeof(TimePicker), typeof(Platforms.Android.MyTimePickerHandler));
#endif
                  }) ;

And the result image:

enter image description here

Liyun Zhang - MSFT
  • 8,271
  • 1
  • 2
  • 14
  • This does not work for me. I am using the TimePicker from a tag. Please see my question at https://stackoverflow.com/questions/76448105/blazor-hybrid-maui-native-android-timepicker thanks a lot! – Smith5727 Jun 10 '23 at 20:48
  • Any thoughts on this @liyun-zhang-msft ? – Smith5727 Jun 12 '23 at 09:02
  • The input is the control in the html and renderered by the webview. And sorry I have no idea about this. @Smith5727 – Liyun Zhang - MSFT Jun 13 '23 at 01:12