有没有办法在旧 android 中使用 -night 资源?
Is there a way to use -night resources in old android?
我想为我的应用程序实现夜间模式,但不想使用任何兼容库。我将资源放在 values-night 文件夹中并使用下一个代码:
UiModeManager systemService = (UiModeManager) this.getSystemService(UI_MODE_SERVICE);
systemService.setNightMode(UiModeManager.MODE_NIGHT_YES);
根据文档,它适用于 API >22,而且确实如此。
是否有强制使用 APIs 15-22 上的 -night 文件夹中的资源的解决方法?
来自documentation for UiModeManager.setNightMode()
:
Note: On API 22 and below, changes to the night mode are only effective when the car
or desk
mode is enabled on a device. Starting in API 23, changes to night mode are always effective.
也许您可以使用其中一种 UI 模式?
AppCompat 库支持它。我不知道你为什么不想使用它。我引用自 Chris Bane's Blog
As you may have seen in the Support Lib 23.2.0 blog post, AppCompat now has a new theme family: Theme.AppCompat.DayNight.
What these themes do is switch between Theme.AppCompat (dark) and Theme.AppCompat.Light (light) based on the time of day. This has many benefits for your users, especially if you’re a content app (it seems to have become a standard feature in Reddit clients). One thing to note is that this feature only actually has an effect when running on an API v14 and later device, on devices before that it will default to the light theme.
我想为我的应用程序实现夜间模式,但不想使用任何兼容库。我将资源放在 values-night 文件夹中并使用下一个代码:
UiModeManager systemService = (UiModeManager) this.getSystemService(UI_MODE_SERVICE);
systemService.setNightMode(UiModeManager.MODE_NIGHT_YES);
根据文档,它适用于 API >22,而且确实如此。 是否有强制使用 APIs 15-22 上的 -night 文件夹中的资源的解决方法?
来自documentation for UiModeManager.setNightMode()
:
Note: On API 22 and below, changes to the night mode are only effective when the
car
ordesk
mode is enabled on a device. Starting in API 23, changes to night mode are always effective.
也许您可以使用其中一种 UI 模式?
AppCompat 库支持它。我不知道你为什么不想使用它。我引用自 Chris Bane's Blog
As you may have seen in the Support Lib 23.2.0 blog post, AppCompat now has a new theme family: Theme.AppCompat.DayNight.
What these themes do is switch between Theme.AppCompat (dark) and Theme.AppCompat.Light (light) based on the time of day. This has many benefits for your users, especially if you’re a content app (it seems to have become a standard feature in Reddit clients). One thing to note is that this feature only actually has an effect when running on an API v14 and later device, on devices before that it will default to the light theme.