warning CA1422: This call site is reachable on: 'Android' 21.0 and later. 'Window.SetStatusBarColor(Color)' is obsoleted on: 'Android' 35.0 and later.
— your .NET MAUI app still supports Android 5.0 (API 21), and the status bar colour call in
MainActivity is obsolete from Android 15 (API 35). Wrap the call in
if (!OperatingSystem.IsAndroidVersionAtLeast(35)) and the warning goes away. A
Build.VERSION.SdkInt check does not silence it.
The build still succeeds, because CA1422 is a warning. The guard loses nothing on new phones: Android's list of Android 15 behaviour changes says "setStatusBarColor and R.attr#statusBarColor are deprecated and have no effect on Android 15" for apps that target API 35 or later, which the MAUI 10 template does.
The error
The line from dotnet build -f net10.0-android; the two absolute paths are shortened, nothing else changed:
...\m1\Platforms\Android\MainActivity.cs(15,16): warning CA1422: This call site is reachable on: 'Android' 21.0 and later. 'Window.SetStatusBarColor(Color)' is obsoleted on: 'Android' 35.0 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1422) [...\m1\M1.csproj::TargetFramework=net10.0-android]
1 Warning(s)
0 Error(s)
The code that triggers it is the classic snippet for painting the status bar:
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Paint the status bar to match the app.
Window?.SetStatusBarColor(Android.Graphics.Color.ParseColor("#512BD4"));
}
Why it happens
Two facts meet at that line. The .NET Android binding marks SetStatusBarColor as
obsoleted from API 35, and the template's SupportedOSPlatformVersion for Android
is 21.0, so every line in the Android target is reachable on 21 and everything after it,
Android 15 included. The platform compatibility analyzer sees a path from Android 15 to an API
that is obsolete there and reports CA1422.
The analyzer recognises the guards its documentation lists: OperatingSystem
checks such as IsAndroidVersionAtLeast, and methods annotated as platform
guards. The Android-style version check compiles and works at runtime, but in this build it
left the warning exactly where it was:
if (Build.VERSION.SdkInt < BuildVersionCodes.VanillaIceCream)
{
Window?.SetStatusBarColor(Android.Graphics.Color.ParseColor("#512BD4"));
}
...\m1\Platforms\Android\MainActivity.cs(17,20): warning CA1422: This call site is reachable on: 'Android' 21.0 and later. 'Window.SetStatusBarColor(Color)' is obsoleted on: 'Android' 35.0 and later.
The fix
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Android 15 (API 35) obsoleted status bar colours: paint it only below 35.
if (!OperatingSystem.IsAndroidVersionAtLeast(35))
{
Window?.SetStatusBarColor(Android.Graphics.Color.ParseColor("#512BD4"));
}
}
Build succeeded.
0 Warning(s)
0 Error(s)
The call now runs only below API 35, and the analyzer can prove it, so the warning is gone in
an incremental build and in a --no-incremental rebuild. On Android 15 and later,
Android's
reference for
Window.setStatusBarColor points you to drawing your own background behind the status
bar insets instead.
The second-best option is #pragma warning disable CA1422 around the call. It
silenced the warning too, but it only hides the message: the call still runs on every
version. The rule's documentation calls suppression safe when you know the obsolete API will
never be called on the affected version, which is exactly what the guard expresses in code.
How it was reproduced
A fresh dotnet new maui project on the .NET SDK 10.0.401 with the android
workload 36.1.69 and Microsoft.Maui.Controls 10.0.20: target framework
net10.0-android, TargetPlatformVersion 36.0, SupportedOSPlatformVersion 21.0 and
targetSdkVersion="36" in the generated manifest. Adding the
OnCreate override above to Platforms/Android/MainActivity.cs and
building only the Android target produced the warning; the guarded version built with zero
warnings. This is build output only: no device or emulator was run, so what Android 15 does
with the call comes from Android's documentation, not from observation. The same warning sat
in the build log of the ClinicLive companion app.
Frequently asked
- How do I fix CA1422 for SetStatusBarColor in .NET MAUI?
- Wrap the call in if (!OperatingSystem.IsAndroidVersionAtLeast(35)). The platform compatibility analyzer recognises OperatingSystem version checks as guards, so the warning disappears and the colour still applies on Android 14 and older.
- Why does a Build.VERSION.SdkInt check not remove the CA1422 warning?
- The platform compatibility analyzer recognises OperatingSystem checks such as IsAndroidVersionAtLeast, and methods annotated as platform guards. A comparison against Build.VERSION.SdkInt works at runtime but is not one of them, and in a .NET 10 MAUI build the warning stayed on the guarded line.
- Can I still change the status bar colour on Android 15?
- Not with SetStatusBarColor. Android's documentation says the call has no effect on Android 15 for apps targeting API 35 or later, and recommends drawing your own background behind the status bar insets instead.
More decoded errors in the Fixes category. If your content now sits under the status bar on Android 15, the native insets fix is in Blazor Hybrid on Android: content hidden under the status bar.