4

Is there anyway, even if requires platform specific code behind, to change the color of both the top bar (the one in blue) and the bottom bar (the one in black)?

I wish to add support for light and dark modes, so I would like to be able to change that during runtime.

Android

Nicke Manarin
  • 3,026
  • 4
  • 37
  • 79
  • https://stackoverflow.com/questions/37993741/xamarin-forms-change-statusbar-color – Anand Apr 18 '19 at 17:42
  • Thanks, but what about the bottom black bar? I saw some apps changing the color of that component, so I think that it's possible. – Nicke Manarin Apr 18 '19 at 19:14

2 Answers2

8

It is possible .

Android:

Using Window.SetStatusBarColor and Window.SetNavigationBarColor can do that easily above Android API 21.

  if (Build.VERSION.SdkInt >= Build.VERSION_CODES.Lollipop)
  {
       Window.SetStatusBarColor(Android.Graphics.Color.Orange);
       Window.SetNavigationBarColor(Android.Graphics.Color.Orange);
   }

enter image description here

IOS:

In ios, change navigation bar and status bar , can use as bellow:

NavigationController.NavigationBar.BarTintColor = UIColor.YouWantColor;
// Color you want, such as UIColor.Green

enter image description here

After click button, changed dynamically to green color.

enter image description here

Junior Jiang
  • 12,430
  • 1
  • 10
  • 30
1

Android

Build.VERSION_CODES.Lollipop is obsolete. Use Android.OS.BuildVersionCodes:

if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
{
  Window.SetStatusBarColor(Android.Graphics.Color.Orange;
  Window.SetNavigationBarColor(Android.Graphics.Color.Orange;
}
Suplanus
  • 1,523
  • 16
  • 30