4

This problem is highly related to the following question: Why are all the dialogs are using the "old" Android 2.x style?

I'm using Delphi Berlin (10.1), where this problem has been fixed already:

enter image description here

But, as soon as a TStyleBook is dropped to the form and assigned to it (e. g. by right clicking a component and then "edit custom style"), the dialog boxes (all of them) turn to the dark style again:

enter image description here

The automatically created "trimmed" style is still the "light" version ("AndroidL Light"). And yes, I checked that function "GetNativeTheme()" in FMX.Helpers.Android.pas assigns the Result, I even copied the file and added it to the project. Removing the assignment from Form1.StyleBook show the native styled dialogs again.

How can this be solved while still keep using a TStyleBook?

Ron Maupin
  • 6,180
  • 4
  • 29
  • 36
StanE
  • 2,704
  • 29
  • 38

2 Answers2

5

I found the problem: Function GetNativeTheme() was searching with TStyleManager.FindStyleDescriptor() in the assigned style for a TStyleDescription object entry, to look if one of the strings "[LIGHTSTYLE]" or "[DARKSTYLE]" is used for the target platform. In a full style file this object entry is normally present, but when starting to edit a custom style of a component inside the IDE, a TStyleBook component is created with just a small style. It cannot be seen inside the IDE, but this small style does not contain the TStyleDescription object entry, so the dark/light theme can not be found out. And by default, the GetThemeFromDescriptor() returns 0, which seems to correspond to the dark/old style.

I solved the problem by double-clicking the TStyleBook component, save the style to a file (*.style), opened the file in a text editor and simply manually added the TStyleDescription object entry. Saved and loaded back to the IDE. Now all dialogs use the correct light style theme.

Add the text marked with the red rectangle to the styles file

Here again as text:

  object TStyleDescription
    StyleName = 'Description'
    Author = 'Embarcadero Technologies Inc.'
    AuthorURL = 'www.embarcadero.com'
    PlatformTarget = '[ANDROID][ANDROIDL][LIGHTSTYLE][DEFINEFONTSTYLES]'
    MobilePlatform = True
    Title = 'AndroidL Light'
    Version = '1.0'
  end
StanE
  • 2,704
  • 29
  • 38
0

In addition to StanE's answer: Instead of adding a StyleDescription to all custom styles you can also modify the GetThemeFromDescriptor() function in FMX.Helpers.Android to return a default value of TJAlertDialog.JavaClass.THEME_HOLO_LIGHT.