1

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

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

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

有没有其他解决方案可以帮助我通过几行代码来限制暗模式以获得风味?

4

1 回答 1

0

您可以获得当前主题,并根据以下方式您可以限制您的应用程序中的黑暗主题

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;
}
于 2019-12-19T06:20:02.527 回答