I have created a little procedure with Delphi 13, to open the system CalendarPicker dialog on Android and was expecting to get that dialog in light mode when Android is in light mode, and in dark mode when Android is in dark mode. Unfortunately, it always shows in light mode. Any suggestions on what I might be doing wrong?
uses System.Sysutils, System.Classes, FMX.Platform,FMX.Pickers; ... procedure OpenDatePicker; var PickerService: IFMXPickerService; DateTimePicker: TCustomDateTimePicker; begin if not TPlatformServices.Current.SupportsPlatformService(IFMXPickerService, PickerService) then raise Exception.Create('Native pickers not supported on this platform'); DateTimePicker := PickerService.Create; DatePicker.Date := Now; DatePicker.ShowMode := TDatePickerShowMode.Date; DatePicker.Show; end;
Delphi uses Theme.Material.Light.NoActionBar as the default app theme for Android apps, and system dialogs (like the date time picker you are invoking) use the app theme by default, ignoring the system theme. You can use the Deployment Manager to override the theme when the system is in dark mode (tested on Delphi 12.3, but should work on 13 as well):
Deploy your app at least once. Inside your project folder locate the styles-v21.xml file (on Android64/Debug or Android64/Release based on your build configuration) and copy it to your project root folder (or somewhere else inside your project that doesn't get overwritten by subsequent deployments).
Edit the file so the parent theme for AppTheme.Base is Theme.Material.NoActionBar (removing the Light qualifier):
<resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="AppTheme.Base" parent="@android:style/Theme.Material.NoActionBar"> <item name="android:windowBackground">@drawable/splash_image_def</item> <item name="android:windowClipToOutline">false</item> </style> </resources>
Add your file to the Deployment Manager setting up these fields (and ensuring the intended build configuration is selected):
Remote Path: res\values-night-v21\
Remote Name: styles.xml
Deploy again and test on your device.
values-night-v21 is a resource qualifier that allows the app to declare resource overrides for dark mode on Android 5.0 onwards. While night is available since Android 2.2, Delphi 13 officially supports Android 13+ devices so declaring the override from 5.0+ is safe.
Alex Sawers