mauicustom-controlsandroid-spinnermaui-android

Customizing a Border Around Pickers for Android on Maui using Handlers and Mappers


I am trying to add a Custom Border around the Picker for Android but my code provided does not seem to be doing anything.

            Microsoft.Maui.Handlers.PickerHandler.Mapper.AppendToMapping("PickerBorder", (handler, view) =>
            {
#if ANDROID
                var border = new Android.Graphics.Drawables.GradientDrawable();
                border.SetShape(Android.Graphics.Drawables.ShapeType.Rectangle);
                border.SetStroke(4, Android.Graphics.Color.Red);
                border.SetCornerRadius(12);
                handler.PlatformView.SetBackground(border);
#elif IOS || MACCATALYST

#elif WINDOWS

#endif
            });

My handler is registered, how I know this is when I only have:

 handler.PlatformView.BackgroundTintList = ColorStateList.ValueOf(Android.Graphics.Color.Transparent);

-added to the Mapper, it does remove the underline in the picker. Would anyone happen to know what I am missing?


Solution

  •         PickerHandler.Mapper.AppendToMapping("Background", (handler, view) =>
            {
                var border = new Android.Graphics.Drawables.GradientDrawable();
                border.SetShape(Android.Graphics.Drawables.ShapeType.Rectangle);
                border.SetStroke(4, Android.Graphics.Color.Red);
                border.SetCornerRadius(12);
    
                handler.PlatformView.Background = border;
            });
    

    Is this the result are you looking for?

    enter image description here

    Tested on .net 9 (Microsoft.Maui.Controls 9.0.14)

    For .net 8, maybe this issue could be helpful