Disable Dark mode in .NET Maui

Govardhan
Jul 4, 2024

--

Some applications need to be in Light mode even the device is in Dark mode, in that cases we have to override the Dark mode feature and display only the Light mode in our applications. There are many ways to do that, here are the possible ways to disable Dark mode.

Use the below code snippet in App.xaml.cs file in the constructor:

Application.Current.UserAppTheme = AppTheme.Light;

If this doesn't work then use the platform specific code to disable the Dark mode.

Dark mode in iOS

Add the following key into the Info.plist in Platform/iOS folder

<key>UIUserInterfaceStyle</key>
<string>Light</string>

Dark mode in Android

In MainActivity.cs add the following into the OnCreate method:

protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
//For Android API under 31
AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo;
//For Android API 31+
var uiModeManager = (UiModeManager)GetSystemService(UiModeService);
uiModeManager.SetApplicationNightMode(1);
}

--

--