3

So I was able to find that you can use depricated code to make the status bar on Android fully transparent:

    var s = SystemUiFlags.LayoutFullscreen | SystemUiFlags.LayoutStable;
    FindViewById(Android.Resource.Id.Content).SystemUiVisibility = (StatusBarVisibility)s;
    Window.SetStatusBarColor(Android.Graphics.Color.Transparent);
    WindowInsetsControllerCompat windowInsetsController = new WindowInsetsControllerCompat(Window, Window.DecorView);
    windowInsetsController.AppearanceLightStatusBars = true;

Since this code is deprecated, how do I achieve the same effect of the top status bar being fully transparent, as matching the background color of whatever picture or color is on the screen at the time. I am using .NET MAUI in VS 2022.

ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
Virang Patel
  • 83
  • 2
  • 10
  • 1
    See https://stackoverflow.com/q/68451704/199364. I won't mark this question as duplicate, because it would be great if you (or anyone) take one of those java answers, and rewrite it in c#. If you get it working, please add it as "Your Answer" below. – ToolmakerSteve May 26 '22 at 19:41

1 Answers1

2

Code that should be on the page:

protected override void OnAppearing()
{
    base.OnAppearing();
#if ANDROID
    MainActivity.SetStatusBarLight(false);
#endif
}

Code in MainActivity.cs

    protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);
    Platform.Init(this, savedInstanceState);

    var s = SystemUiFlags.LayoutFullscreen | SystemUiFlags.LayoutStable;
#pragma warning disable CS0618 // Type or member is obsolete
    FindViewById(Android.Resource.Id.Content).SystemUiVisibility = 
    (StatusBarVisibility)s;
#pragma warning restore CS0618 // Type or member is obsolete
    Window.SetStatusBarColor(Android.Graphics.Color.Transparent);
    WindowInsetsControllerCompat windowInsetsController = new 
    WindowInsetsControllerCompat(Window, Window.DecorView);
    windowInsetsController.AppearanceLightStatusBars = false;

    MainActivityInstance = this;
}

    public static void SetStatusBarLight(bool isLight)
{
    if (MainActivityInstance != null)
    {
        WindowInsetsControllerCompat windowInsetsController =
        new WindowInsetsControllerCompat(MainActivityInstance.Window, MainActivityInstance.Window.DecorView);
        windowInsetsController.AppearanceLightStatusBars = isLight;
    }
}
Virang Patel
  • 83
  • 2
  • 10