You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Problem when trying to disable dark mode on Android. #29387
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)
Reacted by Diego Rodrigues Vieira, Vladislav Bezenson, Joan Serra, Lakshmeesha, Orçun Tuna, Jose G, Maksym Rusynyk, mohsen saremi, Joaquín Rojas, Naveed Ahmed and 5 more
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?
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.
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.
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.
@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.
@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.
Reacted by Mikenso, Nadir Alfakesh, Erick Alexandre, Dymitr Anklewicz, Doddy Rizal Novianto, Emil Mammadov, Edil D. Salvador, Jiří Zdvomka, Ezequiel Fonseca, Aram and 11 more
Reacted by Incode4it and Chandu J S
Reacted by Ezequiel Fonseca, Grigoriy Yanushkovsky and Chandu J S
Reacted by Joaquín Rojas, Aleksey Stroitelev, Rafael Balconi, Augusto Ostapechen, Dymitr Anklewicz, Emil Mammadov, Edil D. Salvador, Ezequiel Fonseca, Grigoriy Yanushkovsky, Chandu J S and 2 more
Reacted by Gibran Dimasagung, Dymitr Anklewicz, Emil Mammadov, Edil D. Salvador, Ezequiel Fonseca, dpnick, Grigoriy Yanushkovsky, James Allan, Chandu J S and Vilson Oga Júnior
Reacted by Joaquín Rojas, Daniel Silva, Dymitr Anklewicz, Emil Mammadov, Edil D. Salvador, Ezequiel Fonseca, dpnick, Grigoriy Yanushkovsky, Chandu J S and Dmitry
That's all, don't forget to delete previous builds. I hope this works for you! Cheers.
Reacted by Fellipe Neves, hd41, lucasalvessantos, Alexis Rojas, Muhammet İpek, MariamMandalyan, Dmitry Kovalev, Pavel, Yusuf Mirkar, Krystian Wybranowski and 1 more
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)
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
Activity
bezenson commentedon Aug 1, 2020
MainApplication have onCreate method. But nothing changes. App still changes colors
joan2404 commentedon Aug 4, 2020
Same problem here... Same React and RN version. Added
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);toonCreate()method onMainApplication.javaand 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?eliasjnior commentedon Aug 10, 2020
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.
chrisglein commentedon Sep 2, 2020
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.
github-actions commentedon Sep 2, 2020
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.
joan2404 commentedon Sep 22, 2020
With RN version 0.63.2 this issue is solved. Checked just now.
ff-joaquin-rojas commentedon Sep 22, 2020
@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.
joan2404 commentedon Sep 30, 2020
@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.
1 remaining item
amerllica commentedon Oct 13, 2020
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
ff-joaquin-rojas commentedon Oct 13, 2020
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!
amerllica commentedon Oct 14, 2020
@ff-joaquin-rojas, I'm Amer known as
amerllicacome from Iran, and actually, it is my pleasure, thank you ❤️ 🌹xXDeonoXx commentedon Nov 10, 2020
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.
Heltonphg commentedon Mar 2, 2021
This does not work for the Xiaomi Mi 9T Pro
singularvoice commentedon Apr 26, 2021
Tnx it's worked:)
mattgle commentedon May 4, 2021
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.xmland add the following line:The file will look like this:
For iOS:
Go to the
Info.plistand add the following code:That's all, don't forget to delete previous builds. I hope this works for you! Cheers.
fellipesnoww commentedon May 5, 2021
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
ronal2do commentedon May 5, 2021
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
AndreyBaryshev commentedon May 19, 2021
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.
Ciberusps commentedon Jul 7, 2021
@AndreyBaryshev thanks a lot
trancongdung12 commentedon Sep 14, 2021
It work for me
sobhanbera commentedon Sep 24, 2021
This worked for me. Thanks for providing this link!