Skip to content

Problem when trying to disable dark mode on Android. #29387

Closed

Description

@RBalconi

Hello people,
I'm learning react / react native and along, making an app to practice. What is happening is that when the device's darkmode is active it implies the colors chosen in the application (an example below). I do not intend to invest time in and do darkmode now, I would like to learn more about React, make the whole app, and then go to the more "superficial" parts and make darkmode within the config of the app itself.

Would it be possible to inhibit / prevent the device's Dark Mode from interfering with the colors of the app?

It's done with my app design 😥

I'm testing the app on a Xiaomi Mi 9T Pro, I also tested it on the S10 + and it didn't happen, it seems that MiUI forces DarkMode ...
Thank you.

React Native version:

"react": "16.11.0",
"react-native": "0.62.2",

Possible solutions that I was unable to make work.

I found the following code below talking to put in the onCreate method of MainActivity.java, however it does not have this method there. I don't know where and how I can do it.
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)

107943046_3977108782364325_148255309064123217_n

Activity

  1. bezenson commented on Aug 1, 2020

    @bezenson

    MainApplication have onCreate method. But nothing changes. App still changes colors

  2. joan2404 commented on Aug 4, 2020

    @joan2404

    Same problem here... Same React and RN version. Added AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);to onCreate() method on MainApplication.java and on Xiaomi the background color changes, which is very bad for the app as it relies on a pure white background. On other devices it works ok. Any clue to a fix?

  3. eliasjnior commented on Aug 10, 2020

    @eliasjnior

    I also have the same problem. I'm running with Expo, also with Xiaomi devices something overrides my styles with Styled Components. Even the splash screen, that's an white SVG, is replaced by a black SVG.

  4. chrisglein commented on Sep 2, 2020

    @chrisglein

    Would it be possible to inhibit / prevent the device's Dark Mode from interfering with the colors of the app?

    I'm certainly no expert on Android's dark mode support, but is there some top-level thing you can declare in the app that opts you out of this? Not a React Native things separately, but just something part of the Android platform that lets you opt out. It should be a standard scenario to have apps that aren't built to handle both light/dark mode and don't want the change in styling. I don't have that answer but maybe StackOverflow is a better resource here? Speak up if you think there's something specific to React Native that's going wrong here.

  5. added
    Resolution: For Stack Overflow
    and removed on Sep 2, 2020
  6. github-actions commented on Sep 2, 2020

    @github-actions

    We are using GitHub issues exclusively to track bugs in the core React Native library. Please try asking over on Stack Overflow as it is better suited for this type of question.

  7. joan2404 commented on Sep 22, 2020

    @joan2404

    With RN version 0.63.2 this issue is solved. Checked just now.

  8. ff-joaquin-rojas commented on Sep 22, 2020

    @ff-joaquin-rojas

    @joan2404 Tried that. It didn't work for me. Checked the changelog and saw there was nothing specific to dark mode on Xiaomi devices. What I have noticed is that it only affects icons and svgs.

  9. joan2404 commented on Sep 30, 2020

    @joan2404

    @ff-joaquin-rojas You're right, it could have been a temporary error of the device. I installed a new build with the latest react native and it worked fine, but after a reboot of the device the problem appeared again. However in my case the probem is with the background, it's pure white and it changes the color to black. Problem not fixed yet.

  10. 1 remaining item

  11. amerllica commented on Oct 13, 2020

    @amerllica

    Dear @RBalconi, the exact solution to turn off the force dark mode on Android is this Stack Overflow post.

    @RigottiG @joan2404 @ff-joaquin-rojas @eliasjnior @inferusvv

  12. ff-joaquin-rojas commented on Oct 13, 2020

    @ff-joaquin-rojas

    Dear @RBalconi, the exact solution to turn off the force dark mode on Android is this Stack Overflow post.

    @RigottiG @joan2404 @ff-joaquin-rojas @eliasjnior @inferusvv

    I don't know who you are or where you came from, but thank you, it works like a charm! You deserve all the best!

  13. amerllica commented on Oct 14, 2020

    @amerllica

    @ff-joaquin-rojas, I'm Amer known as amerllica come from Iran, and actually, it is my pleasure, thank you ❤️ 🌹

  14. xXDeonoXx commented on Nov 10, 2020

    @xXDeonoXx

    does anyone have a solution to a Expo application ? same issue here...

    Edit: the only place i could get this error was Xiaomi MIUI 11.

    image

  15. Heltonphg commented on Mar 2, 2021

    @Heltonphg

    Caro @RBalconi , a solução exata para desligar o modo escuro forçado no Android é esta postagem do Stack Overflow .

    @RigottiG @ joan2404 @ ff-joaquin-rojas @eliasjnior @inferusvv

    This does not work for the Xiaomi Mi 9T Pro

  16. singularvoice commented on Apr 26, 2021

    @singularvoice

    Dear @RBalconi, the exact solution to turn off the force dark mode on Android is this Stack Overflow post.

    @RigottiG @joan2404 @ff-joaquin-rojas @eliasjnior @inferusvv

    Tnx it's worked:)

  17. mattgle commented on May 4, 2021

    @mattgle

    Hey guys! I've found a solution to force the app to stay in Light-theme you just need to follow this steps.

    For Android:
    Go to android/app/src/main/res/values/styles.xml and add the following line:

    <item name="android:forceDarkAllowed">false</item>
    

    The file will look like this:

    <resources>
        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <!-- Customize your theme here. -->
            <item name="android:textColor">#000000</item>
            <item name="android:forceDarkAllowed">false</item>
        </style>
    </resources>
    

    For iOS:
    Go to the Info.plist and add the following code:

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

    That's all, don't forget to delete previous builds. I hope this works for you! Cheers.

  18. fellipesnoww commented on May 5, 2021

    @fellipesnoww

    It worked for me.

    Thanks!

    Don't forget to restart your project and if possible test in a Xiomi Device.
    (Try turn off dark theme with application running after, try turn on the dark theme, just for test)

    If for IOS doesn't work, you will need execute

    pod install
  19. ronal2do commented on May 5, 2021

    @ronal2do
    Contributor

    The solution works for other devices, on Xiaomi case, do not works for TextView or or TextHint from native android layout side, soon as I find a solution I'll post it here

  20. AndreyBaryshev commented on May 19, 2021

    @AndreyBaryshev

    I use expo-splash-screen and fix work only if I add it in two places.
    Without second line fix does'n work for me.
    image

  21. Ciberusps commented on Jul 7, 2021

    @Ciberusps

    @AndreyBaryshev thanks a lot

  22. trancongdung12 commented on Sep 14, 2021

    @trancongdung12
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:forceDarkAllowed">false</item>
        <item name="android:textColor">#000000</item>
    </style>
    <style name="SplashScreenTheme" parent="SplashScreen_SplashTheme">
        <item name="colorPrimaryDark">@color/status_bar_color</item>
    </style>
    

    It work for me

  23. sobhanbera commented on Sep 24, 2021

    @sobhanbera

    Dear @RBalconi, the exact solution to turn off the force dark mode on Android is this Stack Overflow post.

    @RigottiG @joan2404 @ff-joaquin-rojas @eliasjnior @inferusvv

    This worked for me. Thanks for providing this link!

  24. locked as resolved and limited conversation to collaborators on Oct 1, 2021
  25. added
    Resolution: Locked
    on Oct 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Platform: AndroidResolution: For Stack OverflowResolution: Locked

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions