Xamarin表格-IOS-汉堡菜单标题颜色与状态栏不同 [英] Xamarin Forms - IOS - Hamburger Menu Header color differs from Status Bar

查看:91
本文介绍了Xamarin表格-IOS-汉堡菜单标题颜色与状态栏不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Xamarin Forms应用程序中添加了一个汉堡菜单.问题是,对于IOS设备,单击菜单时,状态栏颜色不会像Android菜单上的菜单标题颜色那样更改.您可以在下面的图片中看到不同之处.

I have added a hamburger menu in a Xamarin Forms App. The problem is that for the IOS device, when the menu is clicked the Status Bar Color does not change according to the Menu Header Color as it does for Android. Below you have the images to see the difference.

这是母版页:

<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="MyProject.UI.Pages.Menu.MainPage"
                 xmlns:pages="clr-namespace:MyProject.UI.Pages.Menu"
                 xmlns:calendar="clr-namespace:MyProject.UI.Pages.Calendar;assembly=MyProject"
                 Title="Main">
        <MasterDetailPage.Master>
            <pages:HamburgerMenu x:Name="MasterPage" />
        </MasterDetailPage.Master>
        <MasterDetailPage.Detail>
            <NavigationPage>
                <x:Arguments>
                    <calendar:CalendarPage />
                </x:Arguments>
            </NavigationPage>
        </MasterDetailPage.Detail>
    </MasterDetailPage>

IOS汉堡菜单 Android汉堡菜单

推荐答案

对于android,状态栏的默认颜色是默认显示的状态栏,您可以在Resources文件夹下的Styles.xml文件中找到类似<item name="colorPrimaryDark">#4286f4</item>的颜色

For android its a default color for Statusbar thatsy its showing by default,you can find that like <item name="colorPrimaryDark">#4286f4</item> in your Styles.xml file under Resources Folder.

您可以为iOS手动更改状态栏颜色:
在LoadApplication之前将此代码写入AppDelegate.cs文件中

You can change Statusbar color manually for iOS:
Write this code in your AppDelegate.cs file before LoadApplication

var statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
    if (statusBar.RespondsToSelector(new ObjCRuntime.Selector("setBackgroundColor:")))
    {
        statusBar.BackgroundColor = UIColor.FromRGB(66, 134, 244);
        statusBar.TintColor = UIColor.White;
    }

希望这可以解决您的问题.

Hope this will solve your issue.

这篇关于Xamarin表格-IOS-汉堡菜单标题颜色与状态栏不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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