Jump to content
Nicolò Blunda

App overlaps Android system bar

Recommended Posts

Hi.
This problem seems very common (after searching on Google...)
Compiling with Delphi 12 (custom library migration takes a long time...) and manually inserting android:targetSdkVersion="35" into AndroidManifest.xml (as required by Google Play), my app overlaps the system top bar of device.
With android:targetSdkVersion="34" everything works fine.
There's a workaround in the Delphi code?

Edited by Nicolò Blunda

Share this post


Link to post
3 hours ago, Nicolò Blunda said:

Delphi 12

Presumably you mean 12.0 or 12.1 (also CE) as this issue was "fixed" in 12.2.

 

One workaround is to create a style resource that looks like this:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="AppTheme" parent="AppTheme.Base">
        <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
    </style>
</resources>

Note the windowOptOutEdgeToEdgeEnforcement item which is set to true - this makes your app "opt out" of having it extend all the way to all the edges.

 

If you save the style resource to a file and add it to the deployment using Deployment Manager in Delphi using a Remote Path of \res\values-35 and a name of styles.xml, it should "fix" your problem, for now. I have "fix" in quotes because when targeting API level 36, it will no longer work, however another workaround is discussed here. Please also read the replies that follow it.

  • Like 1

Share this post


Link to post
10 hours ago, Dave Nottage said:

Presumably you mean 12.0 or 12.1 (also CE) as this issue was "fixed" in 12.2.

 

One workaround is to create a style resource that looks like this:


<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="AppTheme" parent="AppTheme.Base">
        <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
    </style>
</resources>

Note the windowOptOutEdgeToEdgeEnforcement item which is set to true - this makes your app "opt out" of having it extend all the way to all the edges.

 

If you save the style resource to a file and add it to the deployment using Deployment Manager in Delphi using a Remote Path of \res\values-35 and a name of styles.xml, it should "fix" your problem, for now. I have "fix" in quotes because when targeting API level 36, it will no longer work, however another workaround is discussed here. Please also read the replies that follow it.

Thank you very much.
My apps works with Embarcadero styles (MyStyle.style file...).
Deplyng app with suggest resource file this error message is rised "error: resource style/AppTheme.Base (aka com.embarcadero.MyProject:style/AppTheme.Base) not found".
Maybe this is a very trivial question (I'm not android expert...).

Share this post


Link to post
11 hours ago, Nicolò Blunda said:

Deplyng app with suggest resource file this error message is rised "error: resource style/AppTheme.Base (aka com.embarcadero.MyProject:style/AppTheme.Base) not found".

Sorry, that resource is from a Delphi 13 deployment. You may need to use this:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="AppTheme" parent="@android:style/Theme.Material.Light.NoActionBar">
        <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
    </style>
</resources>

If that does not work, you may need to use the other workaround

Share this post


Link to post
On 11/9/2025 at 9:52 PM, Dave Nottage said:

Note the windowOptOutEdgeToEdgeEnforcement item which is set to true - this makes your app "opt out" of having it extend all the way to all the edges.

Right, that is the fast solution, to keep everything as-is

https://developer.android.com/reference/android/R.attr#windowOptOutEdgeToEdgeEnforcement

 

I was sure that this option is deprecated in Android 16, but I havent found this again.
This is the only note I've got there at the moment
https://medium.com/@mickcolai/from-android-14-to-15-a-practical-guide-to-adapting-the-legacy-view-system-for-edge-to-edge-a0232d7aea30

 

Quote

Temporary Opt-Out for Edge-to-Edge Enforcement

If you are looking for a quick, short-term solution, there is an opt-out flag available to temporarily disable edge-to-edge enforcement. With this flag, your app will behave as it did in Android 14 or earlier:


<item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>

However, note that Google has stated this flag will be disabled in Android 16.

For apps targeting Android 16, R.attr#windowOptOutEdgeToEdgeEnforcement is deprecated and disabled, and your app can't opt-out of going edge-to-edge.


So probably this is only a temporary solution. :classic_sad:
 

Share this post


Link to post

Simplified of Dave's previous solution 

procedure TForm1.FormCreate(Sender: TObject);
begin
 {$IFDEF ANDROID}
 (* put everyting under a TRectange in Form1 *)
 if (TJBuild_VERSION.JavaClass.SDK_INT >= 35 ) then begin
   Form1.Transparency := True;
   Form1.Padding.Top := 30;
 end;
 {$ENDIF ANDROID}

 

Share this post


Link to post
8 minutes ago, Mustafa ֍zgun said:

Simplified of Dave's previous solution 

So simplified that it assumes that the status bar will always be 30, and completely ignores the navigation bar which is included in my solution.

  • Like 2

Share this post


Link to post
On 11/9/2025 at 7:08 PM, Nicolò Blunda said:

Hi.
This problem seems very common (after searching on Google...)
Compiling with Delphi 12 (custom library migration takes a long time...) and manually inserting android:targetSdkVersion="35" into AndroidManifest.xml (as required by Google Play), my app overlaps the system top bar of device.
With android:targetSdkVersion="34" everything works fine.
There's a workaround in the Delphi code?

Hi. Try this:

procedure ApplySystemInsets(const FForm: TForm);
{$IFDEF ANDROID}
var
  TopHeight, BottomHeight: Integer;
{$ENDIF}
begin
{$IFDEF ANDROID}
  if Assigned(FForm) then
  begin
    TopHeight := GetStatusBarHeight;
    BottomHeight := GetNavigationBarHeight;

    if IsAndroid15OrAbove then
    begin
      FForm.Padding.Top := Round(TopHeight / GetScreenScale);
      FForm.Padding.Bottom := Round(BottomHeight / GetScreenScale);
    end
    else
    begin
      FForm.Padding.Top := 0;
      FForm.Padding.Bottom := 0;
    end;
  end;
{$ENDIF}
end;

function IsAndroid15OrAbove: Boolean;
begin
{$IFDEF ANDROID}
  Result := TJBuild_VERSION.JavaClass.SDK_INT >= 35; 
{$ELSE}
  Result := False;
{$ENDIF}
end;

function GetStatusBarHeight: Integer;
{$IFDEF ANDROID}
var
  ResId: Integer;
begin
  ResId := TAndroidHelper.Context.getResources.getIdentifier(
    StringToJString('status_bar_height'),
    StringToJString('dimen'),
    StringToJString('android')
  );
  if ResId > 0 then
    Result := TAndroidHelper.Context.getResources.getDimensionPixelSize(ResId)
  else
    Result := 0;
end;
{$ELSE}
begin
  Result := 0;
end;
{$ENDIF}

function GetNavigationBarHeight: Integer;
{$IFDEF ANDROID}
var
  ResId: Integer;
begin
  ResId := TAndroidHelper.Context.getResources.getIdentifier(
    StringToJString('navigation_bar_height'),
    StringToJString('dimen'),
    StringToJString('android')
  );
  if ResId > 0 then
    Result := TAndroidHelper.Context.getResources.getDimensionPixelSize(ResId)
  else
    Result := 0;
end;
{$ELSE}
begin
  Result := 0;
end;
{$ENDIF}

function GetScreenScale: Single;
begin
{$IFDEF ANDROID}
  Result := TAndroidHelper.Activity.getResources.getDisplayMetrics.density;
{$ELSE}
  Result := 1;
{$ENDIF}
end;

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×