gpt4 book ai didi

c# - .NET MAUI VISUAL STUDIOS 2022 如何让状态栏全透明

转载 作者:行者123 更新时间:2023-12-05 03:23:59 41 4
gpt4 key购买 nike

所以我发现你可以使用 depricated 代码使 Android 上的状态栏完全透明:

    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;

由于此代码已弃用,我如何实现顶部状态栏完全透明的相同效果,以匹配当时屏幕上任何图片或颜色的背景颜色。我在 VS 2022 中使用 .NET MAUI。

最佳答案

应该在页面上的代码:

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

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;
}
}

关于c# - .NET MAUI VISUAL STUDIOS 2022 如何让状态栏全透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72394044/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com