Letting WebView on Android work with prefers-color-scheme: dark

UPDATE 2022: AndroidX Webkit 1.5.0 fixed a lot of the quirkyness of how webview handles dark mode. For this to work you need to: Add the latest version of webkit to your project (at least 1.5.0): implementation ‘androidx.webkit:webkit:1.5.0’ Set the target version of your application to 33 or up targetSdkVersion 33 Make sure Android System … Read more

How to enable night mode programmatically?

SIMPLEST SOLUTION You can enable/disable application’s dark theme just by: enable dark theme: AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) forcefully disable dark theme: AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) set app theme based on mobile settings of dark mode, i.e. if dark mode is enabled then the theme will be set to a dark theme, if not then the default theme, but this will only … Read more