gpt4 book ai didi

android - 如何在 Android 中限制特定 Flavor 的暗模式

转载 作者:行者123 更新时间:2023-11-30 04:54:56 26 4
gpt4 key购买 nike

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

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

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

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

最佳答案

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

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;
}

关于android - 如何在 Android 中限制特定 Flavor 的暗模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59404114/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com