-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: 🌙 Dark mode not detected in JavaScript and CSS #4677
Comments
Found this plugin that fixes the problem but this should be working on core without any plugins. https://github.com/robingenz/capacitor-android-dark-mode-support |
In one of my projects, I added this piece of code in the int nightModeFlags = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
WebSettings webSettings = this.bridge.getWebView().getSettings();
if (nightModeFlags == Configuration.UI_MODE_NIGHT_YES) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
webSettings.setForceDark(WebSettings.FORCE_DARK_ON);
}
} This is a project with Capacitor 2.x, but this snippet of code might help to be integrated into future versions of Capacitor. |
Hi , but for the IOS ? , any solutions like your dev ? |
For me it depends on the device. On some devices it works on others it doesn't (all on Android 11) |
This problem does not occur on iOS. Only on Android. One simple solution is:
No more steps are necessary. |
I'd be grateful if this could be fixed in core. |
I was having the inverse situation (dark theme won't go away after setting dark theme off on Android). |
The WebView now supports dark mode without native code changes, and match the theme of the app. Capacitor apps use a dark theme by default, so all Capacitor apps will have dark mode enabled by default. If you want to force light mode you can set a light theme by changing this line in
For Capacitor 4 we will change the default theme to use the DayNight so it changes automatically, but since the theme belong to the app and Capacitor doesn't change the user apps after creation, users that want automatic theme change will have to update the style as explained here. We will also document the theme change step on the Capacitor 3 to 4 guide. |
It seems like i need to restart the app after changing the device settings for it to take effect, on windows and ios this updates the app theme immediately. |
I can report the same issue. I can change the theme in the app once anf when I want to change it back the new color theme is not applied. iOS works fine |
+1 |
+2 |
Bug Report
Capacitor Version
Platform(s)
Android
Current Behavior
window.matchMedia('(prefers-color-scheme: light)')
always returns light mode true andwindow.matchMedia('(prefers-color-scheme: dark)')
always returns dark mode false.Expected Behavior
window.matchMedia('(prefers-color-scheme: dark)')
should return true when dark theme is applied to system.Code Reproduction
Initial capacitor project
npm --version
output: 7.15.0node --version
output: v14.17.0Additional Context
possible fix on stackoverflow
The text was updated successfully, but these errors were encountered: