如何根据时间在应用程序的暗黑模式和浅色模式之间进行切换?

huangapple go评论71阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年10月15日 21:44:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/64372950.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定