react-native: Problem when trying to disable dark mode on Android.
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)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 15
- Comments: 22 (1 by maintainers)
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!
@ff-joaquin-rojas, I’m Amer known as
amerllica
come from Iran, and actually, it is my pleasure, thank you ❤️ 🌹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:The file will look like this:
For iOS: Go to the
Info.plist
and add the following code:That’s all, don’t forget to delete previous builds. I hope this works for you! Cheers.
This does not work for the Xiaomi Mi 9T Pro
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.
Tnx it’s worked:)
Same problem here… Same React and RN version. Added
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
toonCreate()
method onMainApplication.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?It work for me
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
@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.
@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.
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.
MainApplication have onCreate method. But nothing changes. App still changes colors