Android dialog boxes in 4.4.x style (XE7)

This simple tip shows how to force Delphi XE7 to use “modern” Android 4.4.x dialog boxes in your mobile applications. Another great tip by David Intersimone from Embarcadero.

If you are creating Android apps using Delphi, even with newest Delphi (RAD Studio) XE7, you may noticed, that standard dialogs looks rather “old” (Android 2.3 style). Changing style book doesn’t help, nor modying the AndroidManifest.xml file. Dialogs looks something like this:

Dialog - old

Dialog – old 2.3 style

But new Android 4.4.x style is different:

Dialog - new style

Dialog – new 4.4.x style

To achieve this, you have to modify GetNativeTheme function in FMX.Helpers.Android.pas unit (“C:\Program Files (x86)\Embarcadero\Studio\15.0\source\fmx“). Modified code looks like this:

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;

It’s beter to let the original file intact and copy modified unit to your project folder and add it to your project using Project Manager.

 

via: David I blog