【问题标题】:How to restrict dark mode for a particular Flavor in Android如何在 Android 中限制特定 Flavor 的暗模式
【发布时间】:2019-12-19 06:10:44
【问题描述】:

我有一个支持暗模式的多种风格的应用。每种风格都从 /main/res 目录的 drawable-night 和 values-night 文件夹中获取深色主题资源。

我现在想限制特定应用风格的暗模式。

第一个解决方案:每个活动在 android:configChanges 属性中都有 uiMode。 第二种解决方案:从 /main/res 中删除 drawable-night 和 values-night 并将其保留为支持它的风味。

还有其他解决方案可以帮助我通过几行代码来限制暗模式吗?

【问题讨论】:

    标签: android android-dark-theme


    【解决方案1】:

    您可以获取当前主题,并根据以下方式在您的应用中限制深色主题

    int currentNightMode = configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK;
    switch (currentNightMode) {
        case Configuration.UI_MODE_NIGHT_NO:
            // Night mode is not active, we're using the light theme
            break;
        case Configuration.UI_MODE_NIGHT_YES:
            // Night mode is active, we're using dark theme
            break;
    }
    

    【讨论】:

      猜你喜欢
      • 2020-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-20
      • 1970-01-01
      • 2020-02-04
      相关资源
      最近更新 更多