Recursive AI

Keep clear of the Android status bar

OneApp is a free, open-source framework for apps in .NET whose UI is HTML and CSS, drawn natively with no web view on Windows, macOS, Linux, iOS and Android, and run in the browser, from Recursive AI. MIT or Apache-2.0, no native DLLs to ship.

Pad your page in MainPage.css.

Terminal
dotnet add package RecursiveAI.OneApp

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

On Android, OneApp sets --safe-area-inset-top to the height of the area covered by the status bar and any top cutout.

CSS
.page {
  padding-top:
    calc(16px + var(--safe-area-inset-top, 0px));
}

The example is the full program below: unzip it and dotnet run.

The header starts below the system bar, with 16 CSS pixels of extra space. dotnet run opens the desktop version; to see the Android inset, use the emulator commands below.

Full program

C#
using OneApp;
 
public static class Program
{
    public static int Main(string[] args)
    {
        using var host = AppHost.Create(new AppOptions(new MainPage())
        {
            Title = "SafeArea",
            AppId = "org.example.safearea",
        });
        host.Run();
        return 0;
    }
}

OneApp builds the MainPage class from MainPage.html and applies MainPage.css when you build the project. The whole markup input is:

HTML
<main class="page">
  <header id="header">Trip notes</header>
</main>

The zip also pads the remaining three edges. box-sizing: border-box includes the padding in the height reserved for the page.

CSS
.page {
  padding-top:
    calc(16px + var(--safe-area-inset-top, 0px));
  padding-right:
    calc(16px + var(--safe-area-inset-right, 0px));
  padding-bottom:
    calc(16px + var(--safe-area-inset-bottom, 0px));
  padding-left:
    calc(16px + var(--safe-area-inset-left, 0px));
  min-height: 100vh;
  box-sizing: border-box;
  background: #e0f2fe;
}
#header {
  background: #075985;
  color: white;
  padding: 12px;
}

This recipe covers Android. The zip’s project file sets <OneAppAndroidTargetSdk>35</OneAppAndroidTargetSdk> to exercise Android 15’s edge-to-edge layout. To run it on Android, install the CLI and use it inside the unzipped project. You need the Android SDK and NDK on Linux x86-64, a booted emulator, and jq for the commands below. The example uses OneApp and the CLI 1.2.1.

Terminal
dotnet tool install -g RecursiveAI.OneApp.Cli
app=$(oneapp run . --android | jq -er .info)
oneapp call computed_style \
  '{"selector":".page","properties":["padding-top"]}' \
  --app "$app"

On the Android 15 emulator:

JSON
{"element":"main.page","values":{"padding-top":"64.76px"}}

Android emulator showing the Trip notes header below the status bar

If a nested header has extra space above it, check that you haven’t added the full top inset to both the page and the header.

Variations

Check the bottom spacing too. Ask the running app for the bottom padding on the same element:

Terminal
oneapp call computed_style \
  '{"selector":".page","properties":["padding-bottom"]}' \
  --app "$app"
JSON
{"element":"main.page","values":{"padding-bottom":"40px"}}

The short answer

Use var(--safe-area-inset-top, 0px) in your OneApp stylesheet. Add it to the normal top padding of the container holding your header. The background can still fill the window behind the system bar while the content starts below it. Use the matching custom property for each other edge that holds content you need to keep clear.

What are window insets?

An inset is a distance inward from an edge of the window. On a phone, the status bar and camera cutout can take space at the top, and the navigation bar can take space at the bottom. Android’s edge-to-edge guide shows the difference between drawing the background behind those areas and letting a button or other control be covered by them.

OneApp puts --safe-area-inset-top, -right, -bottom and -left on the root element in CSS pixels. Use var(...) to read those properties in a OneApp stylesheet; this example doesn’t use the browser’s env(...) function. The 0px fallback supplies a value when the property is absent. The sample keeps its normal spacing even when there is no system inset.

How do I keep my header out of the status bar on Android 15?

Apply the top inset once to the container that owns the header’s spacing. Don’t guess a fixed status-bar height from one emulator or copy a measurement from a screenshot: the variable is already expressed in the units the layout uses. In this run, the total top padding was 64.76px, which includes the sample’s 16px of regular spacing. The remaining 48.76px came from the top inset.

The OneApp 1.2.1 project template already adds the safe-area properties in MainPage.css. If your app uses an older copy of that file or has its own page layout, add the padding where it protects the content rather than changing the Android target SDK to move the entire window.

All oneapp recipes