How to display google maps in dark mode in a .NET MAUI (Android) app

43 views Asked by At

I.m using .NET MAUI's Map control (Microsoft.Maui.Controls.Maps) and I want to reflect the Light/Dark mode of the device. Google maps has a dark mode, but I cannot figure out how to select the dark mode when opening the maå from MAUI (in C#:

   map = new Map(mapSpan)
   {
       MapType = MapType.Street,
       IsShowingUser = true,
       IsScrollEnabled = true,
       IsZoomEnabled = true,
       IsTrafficEnabled = false
    };

    layout.Add(map);)

.NET MAUI documentation on Maps does not include any mentioning of AppThemeBinding or any dark/light mode parameters.

Can anyone help please?

Going through documentation, youtube videos, testing parameters to Map class with no result.

1

There are 1 answers

3
Carrey James On

You can try this codes.

Map map = new Map(mapSpan)
{
    IsShowingUser = true,
    IsScrollEnabled = true,
    IsZoomEnabled = true,
    IsTrafficEnabled = false
};


Application.Current.RequestedThemeChanged += (s, e) =>
{

    AppTheme currentTheme = Application.Current.RequestedTheme;

   
    map.MapType = currentTheme == AppTheme.Dark ? MapType.StreetNight : MapType.Street;
};

layout.Add(map);