Xamarin.Forms.Shell:如何管理StatusBar颜色 [英] Xamarin.Forms.Shell: how to manage StatusBar color

查看:0
本文介绍了Xamarin.Forms.Shell:如何管理StatusBar颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个小型Xamarin.Forms.Shell应用,但我找不到如何将自定义颜色应用于StatusBar前景背景

我的应用程序使用非常基本的配色方案:

  • 前台TabBar
  • 白色代表NavigationBarTabBar背景

我希望StatusBar保持相同的颜色,但情况并非如此:

  • iOS上,StatusBar颜色似乎由LightMode/DarkMode
  • 管理

=&>在不管理暗模式的设备上,或者当亮模式处于活动状态时,StatusBar信息显示良好

=&>但暗模式处于活动状态时情况并非如此,因为这些信息是隐藏的

  • Android上,StatusBar颜色似乎由styles.xaml文件和android:statusBarColor属性管理

=>;如果我指定白色StatusBar信息不可见,因为也有白色

而如果我指定灰色颜色,则StatusBar信息清晰可见

因此我尝试应用给定的解决方案there

  • 这在iOS上不起作用:我仍然有相同的行为,因为StatusBar信息不可见,暗模式处于活动状态时也是白色的
  • 这似乎适用于Android,但这并不适用于所有Android版本(因为它适用于棉花糖版本)

如何管理iOS StatusBar前景色?Android够用吗?

推荐答案

您可以对iOS(黑白状态栏)使用以下方法

    public void SetWhiteStatusBar()
    {
        Device.BeginInvokeOnMainThread(() =>
        {
            if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
            {
                UIView statusBar = new UIView(UIApplication.SharedApplication.KeyWindow.WindowScene.StatusBarManager.StatusBarFrame);
                statusBar.BackgroundColor = UIColor.White;
                UIApplication.SharedApplication.KeyWindow.AddSubview(statusBar);
            }
            else
            {
                UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
                if (statusBar.RespondsToSelector(new ObjCRuntime.Selector("setBackgroundColor:")))
                {
                    statusBar.BackgroundColor = UIColor.White;
                }
            }
            UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.DarkContent, false);
            GetCurrentViewController().SetNeedsStatusBarAppearanceUpdate();
        });
    }

检查我的问题/答案

Xamarin Forms - how to change the status bar color without a navigation page

完整的工作示例在此处https://github.com/georgemichailou/ShaXam

这篇关于Xamarin.Forms.Shell:如何管理StatusBar颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆