Search code examples
datepickermauiunderline

Underline datepicker unfocused Net Maui


I'm building an application in Net Maui and I've noticed that a black line appears below the text in various pickers, datepickers, and entry fields, even when the box is not selected. Why did this line appear? Is there a command to remove it?

Thanks in advance.

Example datepicker

<DatePicker 
        Grid.Row="2"
        BackgroundColor="Beige" 
         HorizontalOptions="Center" 
      VerticalOptions="Center" 
       Grid.Column="1" 
       IsVisible="{Binding IsVisible}"
       Format="dd/MM/yyyy" 
        Date="{Binding dataAllenamento}">
    </DatePicker>

enter image description here


Solution

  • I have created a new project to test the datepicker and found it has no underline on the iOS and windows platform.

    For the android platform, you can use the custom handler to remove the datepicker's underline.

    Create the custom handler in the /Platforms/Android:

     public class MyDatePickerHandler : DatePickerHandler
        {
            protected override void ConnectHandler(MauiDatePicker platformView)
            {
                base.ConnectHandler(platformView);
                GradientDrawable gd = new GradientDrawable();
                gd.SetColor(global::Android.Graphics.Color.Transparent);
                platformView.SetBackground(gd);
               
            }
        }
    

    And use the 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(DatePicker), typeof(Platforms.Android.MyDatePickerHandler));
    #endif
           });