I have an Android App that uses webview, and lately I\'m trying to figure out how to add a dark theme by using the new @media (prefers-color-scheme: dark)
CSS s
What I do, based on your question code, is to force based on current status:
int nightModeFlags = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
if (nightModeFlags == Configuration.UI_MODE_NIGHT_YES) {
webSettings.setForceDark(WebSettings.FORCE_DARK_ON);
}
This way @media (prefers-color-scheme: dark)
works, but @media (prefers-color-scheme: light)
still doesn't work (tried using FORCE_DARK_OFF
and FORCE_DARK_AUTO
in an else)