在网页视图中禁用深色模式

Joh*_*Joe 3 web dart flutter darkmode

我正在 Flutter 中开发一个应用程序(带有 webview),当在设备上激活深色模式时,webview 会更改 web 的颜色(文本和背景)以使其变暗,从而产生可怕的结果。

有没有办法在网页视图中禁用暗模式?

我正在使用这个插件flutter_webview_plugin

Joh*_*Joe 7

我设法通过添加这一行来修复它android/app/src/res/values/styles.xml

<item name="android:forceDarkAllowed">false</item>

这是我的完整代码


<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <!-- Show a splash screen on the activity. Automatically removed when
             Flutter draws its first frame -->
        <item name="android:forceDarkAllowed">false</item>
        <item name="android:windowBackground">@drawable/launch_background</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

  • 当它添加到 android/app/src/main/res/values/styles.xml 和 android/app/src/main/res/values-night/styles.xml 时它就起作用了。谢谢!你救了我的命。 (3认同)