1

I made a webview app and disable Dark Mode with the following:

 WebSettingsCompat.setForceDark(settings, WebSettingsCompat.FORCE_DARK_OFF);

The problem starts when I changed to targetSdk 33. This method is deprecated and I tried the following:

if (SDK_INT >= 33) {
        if (WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING)) {
            WebSettingsCompat.setAlgorithmicDarkeningAllowed(settings, false);
        }
    }else{
        if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
            WebSettingsCompat.setForceDark(settings, WebSettingsCompat.FORCE_DARK_OFF);
        }
    }

After this I installed the app in my phone (Xiaomi Redmi 8T) and dark mode destroyed my app.

After that I tried a lot of things that I found here but nothing worked.

  • I tried to copy themes.xml to dark/themes.xml

  • I tried to add this to onCreate:

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);

  • I tried to add this on themes.xml

    <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>

  • I tried to change Theme.MaterialComponents.DayNight.DarkActionBar to Theme.MaterialComponents.Light.DarkActionBar

  • I tried all of them together

But nothing worked... Why is so difficult to add just a simple choice for disabling Dark Mode.

UPDATE

I have problem with dark mode on my phone but the app worked perfect on android studio emulator.

After that I realized that there is a problem on MIUI (Xiaomi) and found a solution here: So I tried to find a solution and finally I found one here: https://stackoverflow.com/a/66640823/6281778

0 Answers0