Disable Dark mode

Bhuwan 881 Reputation points
2022-09-12T12:18:00.103+00:00

Hi,

My mobile application always use light mode so if i change Android Brightness light to dark then my Application not convert to light to dark, it's always show light theme.

so how to disable in Microsoft MAUI.

Developer technologies .NET .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2022-09-13T02:37:02.483+00:00

    Hello,

    My mobile application always use light mode so if i change Android Brightness light to dark then my Application not convert to light to dark, it's always show light theme.

    Did you mean you want to know how to switch the AppTheme to fit the Android system theme?

    If so, please refer to Respond to system theme changes. This official documentation and sample should be helpful for you.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


2 additional answers

Sort by: Most helpful
  1. Bhuwan 881 Reputation points
    2022-09-13T07:37:07.77+00:00

    Hi @Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) as per suggested in your first comment i am working changes like this. now it's working.

    https://learn.microsoft.com/en-us/dotnet/maui/user-interface/system-theme-changes

    in App.xaml.cs

    i am using below code

    Application.Current.UserAppTheme = AppTheme.Light;

    Thanks


  2. Dustin 41 Reputation points
    2022-09-26T13:06:15.823+00:00

    To disable dark mode use following methode:

    In MainActivity.cs add the folowing into the OnCreate Methode:

    protected override void OnCreate(Bundle bundle)
    {
    var uiModeManager = (UiModeManager)GetSystemService(UiModeService);
    uiModeManager.SetApplicationNightMode(1);

    }

    1 disables dark mode for the whole App (only Android 31+)

    For more Information you can look at Android Docs:
    https://developer.android.com/reference/android/app/UiModeManager#setNightMode(int)

    For everything under Android 31 use:
    ((AppCompatActivity)this).Delegate.SetLocalNightMode(AppCompatDelegate.ModeNightNo);

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.