How to get Android 4.4.x style for your XE7 dialog boxes

Posted by on in UI

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.

Capture

Build your app and see the modern dialog boxes on your Android KitKat devices.

Screenshot 2014-12-29-11-57-48

Thanks for pointing out the issue, Hebron, and for using the new Community 3.0 Answers section.

 



About
Gold User, Rank: 1, Points: 2466
David Intersimone (known to many as David I.) is a passionate and innovative software industry veteran-often referred to as a developer icon-who extols and educates the world on Embarcadero developer tools. He shares his visions as an active member of the industry speaking circuit and is tapped as an expert source by the media. He is a long-standing champion of architects, developers and database professionals and works to ensure that their needs are folded into Embarcadero's strategic product plans. David holds a bachelor's degree in computer science from California Polytechnic State University at San Luis Obispo, California.

Comments

  • Ross T1998
    Ross T1998 Friday, 23 January 2015

    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.

  • &gt; Rich &lt;703
    > Rich <703 Friday, 2 January 2015

    Nice!

    visualdelphi.wordpress.com

  • Please login first in order for you to submit comments
  • Page :
  • 1

Check out more tips and tricks in this development video: