How to get Android 4.4.x style for your XE7 dialog boxes
Over the holidays, Hebron posted a question using the Embarcadero Community 3.0 Answers section. He asked "Why all the dialogs are using the "old" Android 2.x style? And how to force my Android app to use the 4.4.x style in all the dialogs like date picker and MessageDlg? Using StyleBook and modying the AndroidManifest.xml doesn't work. I am currently using XE7. Thanks in advance." I did some testing at my home office and confirmed that there was an issue. I sent an email to our FireMonkey R&D team members and they confirmed the issue and provided the answer.
The fix is very simple : In the FMX.Helpers.Android.pas unit, you need to modify the GetNativeTheme function. Here is the modified code:
function GetNativeTheme: Integer; var LStyleDescriptor: TStyleDescription; begin Result := 0; if not IsGingerbreadDevice and (Screen <> nil) and (Screen.ActiveForm <> nil) and (Screen.ActiveForm.StyleBook <> nil) then begin LStyleDescriptor := TStyleManager.FindStyleDescriptor(Screen.ActiveForm.StyleBook.Style); // the original code -->GetThemeFromDescriptor(LStyleDescriptor); // the next line has the modified code to set the result Result := GetThemeFromDescriptor(LStyleDescriptor); end; end;
Note: update based on community answers comment - in the same FMX.Helpers.Android.pas unit there is an overloaded GetNativeTheme function right after the one listed above. Make the same change to the source code for the overloaded function. Thank you Apostolos!
function GetNativeTheme(const AControl: TControl): Integer; var LStyleDescriptor: TStyleDescription; begin Result := 0; if not IsGingerbreadDevice then begin LStyleDescriptor := TStyleManager.GetStyleDescriptionForControl(AControl); // GetThemeFromDescriptor(LStyleDescriptor); Result := GetThemeFromDescriptor(LStyleDescriptor); // <--here the result assignment was missing end; end;
You will find the original source code unit in the "C:\Program Files (x86)\Embarcadero\Studio\15.0\source\fmx" folder. Copy the "FMX.Helpers.Android.pas" source file to your project and modify the line to set the return Result.
Add the source file to your project in the IDE.
Build your app and see the modern dialog boxes on your Android KitKat devices.
Thanks for pointing out the issue, Hebron, and for using the new Community 3.0 Answers section.


Is there any way to conditionally include this modified file ?
I have an app that is designed to be used on Android, iOS and windows, which will not compile if I set the target to anything other than Android.