Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey, Delphi Android, Delphi IOS

Change The StatusBar Color Property For FireMonkey In Delphi 10 Berlin On Android

| Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOS

statusbarcolor | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSDeveloper ZuBy has made some demo code available for changing the StatusBar color on Android in your apps. The status bar is the bar at the top of your device with the various icons and other information in it. In a Java based Android app to change StatusBar color you can do it either by modifying the styles.xml file and adding the following line: <item name=”android:statusBarColor”>@color/color_primary</item> or by changing at runtime (implementations may differ) through code using window.setStatusBarColor(activity.getResources().getColor(R.color.my_statusbar_color)). However, in FireMonkey you must use the JNI (Java Native Interface). JNI enables Java code running in a Java Virtual Machine (JVM) to call and be called by native applications (programs specific to a hardware and operating system platform) and libraries written in other languages. Thus, you can call JNI Java code from Delphi 10 Berlin with FireMonkey and make the necessary changes. In order to make use of this change, make sure you are using Android 5 (Lollipop) and above. This code does not apply to Windows, IOS, or OSX. Notice that the code bellow is very similar to the Java implementation on Android.

procedure StatusBarSetColor(const aColor: TAlphaColor);
{$IFDEF ANDROID}
var
  Window: JWindowExt;
{$ENDIF}
begin
{$IFDEF ANDROID}
  CallInUIThread(
    procedure
    begin
      if TOSVersion.Check(5, 0) then
      begin
        Window := GetWindowExt;
        Window.addFlags(TJWindowManager_LayoutParams.JavaClass.FLAG_TRANSLUCENT_STATUS);
        Window.addFlags(TJWindowManager_LayoutParamsExt.JavaClass.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

        Window.setFlags(TJWindowManager_LayoutParams.JavaClass.FLAG_TRANSLUCENT_STATUS,
          TJWindowManager_LayoutParams.JavaClass.FLAG_TRANSLUCENT_STATUS);
        Window.setFlags(TJWindowManager_LayoutParamsExt.JavaClass.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
          TJWindowManager_LayoutParamsExt.JavaClass.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

        Window.setStatusBarColor(TJcolor.JavaClass.TRANSPARENT); );
      end;
    end);
{$ENDIF}
{$IFDEF IOS}
  SetStatusBarBackgroundColor(aColor);
{$ENDIF}
end;

Head over to checkout the full demo on how to change the StatusBar color in Delphi 10 Berlin with FireMonkey

Edit: For changing the StatusBar color on IOS check out this Github code.

Exit mobile version