即使没有设置夜间模式,也会参考黑暗模式的值。

问题描述 投票:0回答:1

即使没有设置暗色模式,应用程序也会引用 values-night 文件夹中的值。

values-night 文件夹中的 colors.xml 文件。

    <?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="application_background_color">#000000</color>
</resources> <!-- $Id$ -->

value文件夹中的color.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="application_background_color">#FFFFFF</color>
</resources> <!-- $Id$ -->

但这并不是每次都能重现。它是间歇性地重现。

android android-theme
1个回答
0
投票

使用

 class MyApplication : Application() {

          override fun onCreate() {
                super.onCreate()
                val nightModeEnabled = //get value from shared prefs or wherever you are storing this flag
                if (nightModeEnabled) {
                    Timber.d("Manually instantiating WebView to avoid night mode issue.");
                    try {
                        WebView(applicationContext)
                    } catch (e: Exception) {
                        Timber.e("Got exception while trying to instantiate WebView to avoid night mode issue. Ignoring problem.", e)
                    }
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
                }
          }
        }
© www.soinside.com 2019 - 2024. All rights reserved.