首页 > 解决方案 > 如何在 Delphi macOS 应用程序中检测暗模式

问题描述

如何在 Delphi Firemonkey macOS(例如 Big Sur)应用程序中检测暗模式?

Lazarus 有代码,但 Firemonkey 没有。

标签: macosdelphimacos-big-surdarkmode

解决方案


您可以使用 FireMonkey 平台服务来获取该信息:

uses
  FMX.Platform;

function GetSystemTheme: TSystemThemeKind;
var
  LService: IFMXSystemAppearanceService;
begin
  Result := TSystemThemeKind.Unspecified;
  if TPlatformServices.Current.SupportsPlatformService(IFMXSystemAppearanceService, LService) then
    Result := LService.GetSystemThemeKind;
end;

在哪里TSystemThemeKind声明为

TSystemThemeKind = (Unspecified, Light, Dark); 

IFMXSystemAppearanceService目前支持 Android、iOS 和 macOS。


推荐阅读