0

I am trying to change the color of top/notification bar on Xamarin Forms Portable Class Library. I have tried using the following:

 MainPage.SetValue(NavigationPage.BarTextColorProperty, Color.FromHex(#424242);

Source: Xamarin.Forms - Change StatusBar Color

I have also tried using

    public App()
{
    MainPage = new NavigationPage(new Page1())
    {
        BarBackgroundColor = Color.FromHex("#424242"),
        BarTextColor = Color.White,
    };
}

Source: https://theconfuzedsourcecode.wordpress.com/2016/02/12/setting-the-navigationbar-colors-in-xamarin-forms/

In first instance/code the app launches, however gets stuck at loading screen. Am also new to using Xamarin, so unsure where to find error logs for this as none were displayed in the console.

In the second instance/code the app colors the area on top of the application/under the notification bar but not the notification bar itself.

Hope someone can guide me in the right direction.

Thanks

Community
  • 1
  • 1
SakshamInABox
  • 79
  • 2
  • 13
  • Have you checked my answer? Any problem? – Grace Feng Apr 25 '17 at 09:58
  • Hey, yeah I tried it and launched on Nexus emulator, the system bar still comes up in default (blue color). I rebuilt/cleaned the solution, not sure what I am doing wrong. Appreciate the help btw :) – SakshamInABox Apr 25 '17 at 12:03
  • Which android version is your emulator's OS? – Grace Feng Apr 26 '17 at 01:36
  • Android 5.0 I think – SakshamInABox Apr 26 '17 at 05:07
  • Then my solution should work, as you can see from [setStatusBarColor](https://developer.android.com/reference/android/view/Window.html#setStatusBarColor%28int%29), it is supported from API level 21. And you can check the [test result](https://i.stack.imgur.com/wCb4Z.png) of my code. You can also check [this similar thread on SO](http://stackoverflow.com/questions/26702000/change-status-bar-color-with-appcompat-actionbaractivity). – Grace Feng Apr 26 '17 at 05:39

1 Answers1

3

Your first method is trying to change the text color(so to say "foreground color") of notification bar and your second method is trying to change the background color of navigation bar, and since you said:

In the second instance/code the app colors the area on top of the application/under the notification bar but not the notification bar itself.

I guess that you want to change the background color of system's status bar, not the one of application's navigation bar. Then you can only change it in your android project, not in PCL.

For example, open your MainActivity of android project and modify the OnCreate method like this:

protected override void OnCreate(Bundle bundle)
{
    TabLayoutResource = Resource.Layout.Tabbar;
    ToolbarResource = Resource.Layout.Toolbar;

    base.OnCreate(bundle);

    global::Xamarin.Forms.Forms.Init(this, bundle);
    LoadApplication(new App());

    Window.ClearFlags(WindowManagerFlags.TranslucentStatus);
    Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
    Window.SetStatusBarColor(Color.LightPink);
}
Grace Feng
  • 16,564
  • 2
  • 22
  • 45