Created
November 24, 2021 11:59
-
-
Save TorkelV/3ed7f287a53796566399fcb70cb8ff47 to your computer and use it in GitHub Desktop.
enable dark mode in android WebView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
webView.run { | |
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK_STRATEGY) | |
&& (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES | |
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | |
WebSettingsCompat.setForceDarkStrategy(settings, WebSettingsCompat.DARK_STRATEGY_WEB_THEME_DARKENING_ONLY) | |
settings.forceDark = WebSettings.FORCE_DARK_ON | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment