Maui icon indicating copy to clipboard operation
Maui copied to clipboard

[BUG] StatusBarBehavior - StatusBarColor not working (only android sdk 30)

Open pawelt94 opened this issue 9 months ago • 2 comments
trafficstars

Is there an existing issue for this?

  • [x] I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

  • [x] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug

Current Behavior

When I set StatusBarColor to Transparent it only on android sdk 30 does not work properly - statusbar and navigation bar bottom is not transparent.

Android SDK 31 Android SDK 29 Android SDK 30

In the sample project, I just added:

    <ContentPage.Behaviors>
        <toolkit:StatusBarBehavior StatusBarColor="Transparent" StatusBarStyle="LightContent" />
    </ContentPage.Behaviors>

Expected Behavior

Behavior exactly the same as in android sdk 29 or 31

Steps To Reproduce

Open and run solution from reproduction repo. StatusBarBehavior is added in MainPage

Link to public reproduction project repository

https://github.com/pawelt94/androidbugStatusBarBehavior

Environment

- .NET MAUI CommunityToolkit: 11.1.O
- OS: Android SDK 30
- .NET MAUI: maui-android 9.0.14/9.0.100, SDK 9.0.100

Anything else?

No response

pawelt94 avatar Feb 18 '25 14:02 pawelt94

Same issue here

Speedexx avatar Feb 26 '25 08:02 Speedexx

Have u tested on a physical device? The behavior for status bar on emulators are currently inconsistant with actual devices. What type of devices have u tested? Samsung/Google? I have found that status bar behavior can change depending on device settings too. Do you use gesture navigation? Or do u have navbar buttons enabled? All of this affects the behavior of status bar and the emulator does not behave as expected during testing.

It is best to test on a real device and see if the issue persists. If it does can u identify whether gesture navigations are turned on and what device it is?

ne0rrmatrix avatar Feb 26 '25 12:02 ne0rrmatrix

I've facing the same issue. Statusbar color works for iOS but not Android.

brian-smith723 avatar Jul 19 '25 08:07 brian-smith723

I have this that works on (Android API 36) .Net 9 Maui but on .Net 10 RC2 it is not working.

<?xml version="1.0" encoding="UTF-8" ?>
<Shell
    x:Class="MauiAppNet10.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:MauiAppNet10"
    xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
    Title="MauiAppNet10" >
    
    <Shell.Behaviors >
        <toolkit:StatusBarBehavior
        StatusBarColor="{AppThemeBinding Light=Blue, Dark=Black}"
        StatusBarStyle="{AppThemeBinding Light=DarkContent, Dark=LightContent}"
        ApplyOn="OnPageNavigatedTo" />
    </Shell.Behaviors>
    
    <TabBar>
        <ShellContent
            Title="Home"
            ContentTemplate="{DataTemplate local:MainPage}"
            Route="MainPage" />
        <ShellContent
            Title="Setting"
            ContentTemplate="{DataTemplate local:SettingPage}"
            Route="MainPage" />
    </TabBar>
    
</Shell>

alberk8 avatar Nov 02 '25 01:11 alberk8

I'm also hitting this bug on .Net 10 RC2. It appears to be related to the fact that Android is now enforcing edge-to-edge, and this library hasn't been updated to handle it yet. I have the following fix in place that seems to work.

private void SetSystemBarsAppearance()
{
    if (OperatingSystem.IsAndroidVersionAtLeast(35))
    {
        var decorView = Window.DecorView;

        var statusBarColor = (MauiApp.Current?.Resources.TryGetValue("StatusBarColor", out var colorResource) ?? false)
            ? (Color)colorResource
            : Colors.White;

        decorView.SetBackgroundColor(statusBarColor.ToPlatform());
        
        WindowInsetsControllerCompat windowInsetsController = new(Window, decorView);
        
        // Set to true for dark icons on a light background, false for light icons on a dark background
        windowInsetsController.AppearanceLightStatusBars = statusBarColor.GetLuminosity() > 0.5; 
    }
}

protected override void OnCreate(Bundle savedInstanceState)
{
    SetSystemBarsAppearance();

    base.OnCreate(savedInstanceState);
}

"MauiApp" is a using alias: using MauiApp = Microsoft.Maui.Controls.Application;

I'm doing the color lookup from my App.xaml resource dictionary.

Haven't tested below 35 yet.

ahoffmandevelopment avatar Nov 05 '25 18:11 ahoffmandevelopment

Thanks @ahoffmandevelopment! I've added this fix to our .NET 10 PR: https://github.com/CommunityToolkit/Maui/pull/2902/commits/b5add8ac4fe93eab51997e8ee8c24dead467779c

I've marked these comments regarding .NET 10 as Resolved and kept this Issue open since this Issue is specifically referring to behavior on Android SDK 30.

TheCodeTraveler avatar Nov 05 '25 19:11 TheCodeTraveler