ios - Xamarin.Forms NavigationBar 颜色自 iOS 4.6 以来被覆盖
问题描述
由于我已更新到 Xamarin.Forms 4.6,我的 NavigationBar 颜色会被我无法弄清楚的任何来源覆盖。
我正在根据当前主题(暗/亮)设置 BarTintColor,如下所示:
this.NavigationController.NavigationBar.BarTintColor = Color.FromHex("#212121").ToUIColor();
但它不断被纯黑色或灰色(取决于深色/浅色)覆盖。我也尝试通过设置它UINavigationBar.Appearance.BarTintColor
,也没有改变。此外,我正在设置 TintColor(条形的字体颜色),如下所示:
this.NavigationBar.TintColor = UIColor.FromRGB(38, 100, 137);
当我启动应用程序时它工作正常,但是一旦我在我的应用程序中导航到其他地方,它就会变回默认的系统蓝色。
解决方案
在 Xamarin Forms 中,有一种直接的方法可以修改NavigationBar
in的颜色App.xaml.cs
。
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage())
{
BackgroundColor = Color.Yellow,
BarTextColor = Color.Black
};
}
效果:
如果需要修改状态栏的颜色,可以编写AppDelegate.cs
如下代码:
public override void OnActivated(UIApplication uiApplication)
{
if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
// If VS has updated to the latest version , you can use StatusBarManager , else use the first line code
// UIView statusBar = new UIView(UIApplication.SharedApplication.StatusBarFrame);
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.StatusBarStyle = UIStatusBarStyle.BlackOpaque;
}
}
base.OnActivated(uiApplication);
}
效果:
推荐阅读
- c - Bash 没有为可执行文件设置内存
- html - 带顺风的类 text-white 不起作用
- python - 如果我不调用 super().__init__(),自定义异常类的父级如何获取参数?
- typescript - 链接观察者 RxJs
- java - java:错误:不支持发布版本 17
- javascript - 如果 url 以 / 开头,则 Ajax 调用不会为 window.location.href 加上前缀
- owl-carousel - 我如何在 owl carousel 中的每张幻灯片上显示 4 个项目
- javascript - Svelte js with store and Prism library issue
- typescript - 摩纳哥编辑打字稿不提供建议
- database - 如何编辑数据库中存在数据的数据?在代码点火器 3 上