英文:
How to change app between dark mode and light mode depending on the time of day?
问题
显然您可以使用以下内容:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_TIME);
但是 MODE_NIGHT_AUTO_TIME
已被弃用。
根据当前时间自动切换深色/浅色模式已不推荐使用。建议考虑使用明确的设置,或者使用
MODE_NIGHT_AUTO_BATTERY
。
为什么这样一个很棒的功能会被弃用呢?还有他们提到的“明确的设置”是什么替代方案呢?
英文:
Apparently you can use this:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_TIME);
But MODE_NIGHT_AUTO_TIME
is depreciated.
> Automatic switching of dark/light based on the current time is deprecated. Considering using an explicit setting, or MODE_NIGHT_AUTO_BATTERY.
For what possible reason could such an amazing function be depreciated? And what is the alternative "explicit setting" they talk about?
答案1
得分: 1
如果您按照支持深色模式的指南进行操作,则无需担心深色/浅色模式的问题。
用户可以设置时间表,用于指定设备何时切换模式,然后应用程序主题将相应地进行调整,因此不再需要额外处理这个。
英文:
If you are following the guidelines for supporting dark mode you do not need to worry about if/when its dark/light mode.
The user can setup schedules for if/when the device switches between modes and then app themes will adapt accordingly hence there is no need for that anymore
答案2
得分: 1
我猜最好还是遵循系统设置。如果系统使用深色模式,您的应用程序将自动切换到深色模式,因为大多数设备支持计划深色模式。如果您希望您的应用程序随时间切换,我猜您必须手动执行,比如在初始化视图之前检查时间并决定是否使用深色模式或浅色模式。
英文:
I guess it's better to follow the system settings. If the system is using dark mode, you app will automatically switch to dark mode since most devices support schedule dark mode. If you want your app to switch with time, I guess you have to do it manually like check the time before initializing your views and decide whether to use dark mode or light mode.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论