Dark Mode Not working (Capacitor)

Hello, i started a new Capacitor project and then i deployed it to Android and dark-mode doesn’t seem to work, it just restarts the app with no effect. Any ideas?

Capacitor is a native runtime, so Dark Mode is implemented in your web code. See here for details on how to do that.

1 Like

It’s a bug on android webview or wrong behavior.
Here you can see some tips to make it work

1 Like

If you want to dynamically listen to changes in the dark mode on android, you can use the plugin I’ve developed. In opposition to checking whether dark mode has been enabled during app launch, the plugin will allow you to listen to changes in the dark mode even while your app is running. Also, there is no need to target sdk 29. I’ve tested the plugin by targeting sdk 28 and it works fine.

Hi, I resolve automatic dark theme switch in android by adding

@Override
  public void onResume() {
    super.onResume();
    int nightModeFlags = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
    WebSettings webSettings = this.bridge.getWebView().getSettings();

    if (nightModeFlags == Configuration.UI_MODE_NIGHT_YES) {
      if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
        webSettings.setForceDark(WebSettings.FORCE_DARK_ON);
      }
    } else {
      webSettings.setForceDark(WebSettings.FORCE_DARK_OFF);
    }
  }

on MainActivity

2 Likes