Xamarin Forms - IOS - Hamburger Menu Header color differs from Status Bar

随声附和 提交于 2020-01-15 08:43:25

问题


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.

This is the masterpage:

<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 Hamburger menu, Android Hamburger menu


回答1:


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.

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.



来源:https://stackoverflow.com/questions/49980367/xamarin-forms-ios-hamburger-menu-header-color-differs-from-status-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!