'WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK) returns false

I'm trying to add a dark theme to my app (which uses an Android web view) but whenever I call to check WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK) to see if my web view supports it, it returns false. I'm running on a simulator with API version 29, and my app has a target version of 29 with a min version of 16. How can I make sure this method returns true?



Solution 1:[1]

According to the accepted answer of Letting WebView on Android work with prefers-color-scheme: dark

The isFeatureSupported check is to make sure the Android System WebView version the user has installed on their device supports dark mode (since this can be updated or downgraded independently from the Android version through Google Play)

So in my case, after I updated Android System Webview on the device/emulator, the issue was resolved. If you have problem to update the app (for example, update pending problem), please check whether the app has auto-update enabled. Check auto-update of app in Google Playstore. For more possible solutions to update problems, please refer to this article: Fix: Chrome and Android System Webview is not getting updated

My running environment:

  • minSdk 23
  • targetSdk 31
  • Pixel 3 API 29

Hope it helps!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bruce Lawliet