Skip to content

Instantly share code, notes, and snippets.

@TorkelV
Created November 24, 2021 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TorkelV/3ed7f287a53796566399fcb70cb8ff47 to your computer and use it in GitHub Desktop.
Save TorkelV/3ed7f287a53796566399fcb70cb8ff47 to your computer and use it in GitHub Desktop.
enable dark mode in android WebView
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