0
votes

I've tried everything.

App.xaml

<Application.Resources>
    <ResourceDictionary>
        <Style TargetType="NavigationPage">
            <Setter Property="BarBackgroundColor" Value="#00ff00"/>
        </Style>
    </ResourceDictionary>
</Application.Resources>

App.xaml.cs

public App ()
{
    InitializeComponent();
    MainPage = new NavigationPage(new HomePage())
    {
        BarBackgroundColor = Color.Green // doesn't work
    };
}

AppDelegate.cs

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    global::Xamarin.Forms.Forms.Init();

    LoadApplication(new App());

    UIKit.UIApplication.SharedApplication.SetStatusBarStyle(UIKit.UIStatusBarStyle.BlackOpaque, false); // doesn't have to be black. im just trying to get it to change to any color at all.

    return base.FinishedLaunching(app, options);
}

info.plist

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

¯\_(ツ)_/¯ ‏‏‎ ‏‏‎ ¯\_(ツ)_/¯ ‏‏‎ ‏‏‎ ¯\_(ツ)_/¯ ‏‏‎ ‏‏‎ ¯\_(ツ)_/¯ ‏‏‎ ‏‏‎ ¯\_(ツ)_/¯ ‏‏‎ ‏‏‎ ¯\_(ツ)_/¯ ‏‏‎ ‏‏‎ ¯\_(ツ)_/¯

Nothing does anything at all. It always looks like this.

enter image description here

To be clear it should look like this.

enter image description here

2
didn't work. the only real new thing was GetCurrentViewController().SetNeedsStatusBarAppearanceUpdate();. ...it's still does absolutely nothing. you'd think it would throw an error or something instead of doing nothing.user875234

2 Answers

1
votes

It is possible to change the status bar background color on iOS but it is a bit hacky.

var statusBarView = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
statusBarView.BackgroundColor = UIColor.Green;

Also, if your app rotates you will have to set that value again and keep in mind I'm not sure how fond Apple will be during app submission of you changing the color.

0
votes

So I gave up.

One problem is the status bar height is different depending on the device. What I did was put a BoxView under the status bar and then set its height at runtime.

.xaml

<BoxView x:Name="StatusBarBackground" BackgroundColor="Yellow" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>

.cs

StatusBarBackground.Height = (int)UIKit.UIApplication.SharedApplication.StatusBarFrame.Height;