'Android DarkMode Strategy selection does not work with Cordova (prefers-color-scheme)
I am using Cordova for Android App. I load a webpage on CordovaWebView which has dark mode css defined as @media(prefers-color-scheme). Android does not respect the Webpage Dark Scheme. (<head> has <meta name="color-scheme" content="dark light">)
There are two stategy of DarkMode that Android supports.
- Color-Inversion (DARK_STRATEGY_USER_AGENT_DARKENING_ONLY)
- Webpage scheme (DARK_STRATEGY_WEB_THEME_DARKENING_ONLY)
And Android lets you decide the dark mode strategy using this code
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK_STRATEGY)) {
WebSettingsCompat.setForceDarkStrategy(webView.getSettings(), WebSettingsCompat.DARK_STRATEGY_WEB_THEME_DARKENING_ONLY);
}
But it does not seem to work with Cordova WebView. (I tested this code with WebView. It works fine).
What am I missing here? Is this a Cordova Bug? I found something on Cordova Github Bug Report . But I did not find any solution.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
