Xamarin.Forms - Change StatusBar Color

xamarin forms status bar text color
xamarin android change status bar color programmatically
xamarin forms title bar color
xamarin forms navigation bar color
xamarin forms shell status bar color
xamarin forms bar color
xamarin forms android status bar background color
change status bar icon color android

I search but I can't find if it's possible to change the StatusBar color for each platform, from my portable code? (for Android, iOS & WinPhone 8.1)

public App()
{
    // Change the StatusBar color
    MainPage = new MainPageUser();
}

I'm coming back to this answer years later to fix it because my answer had been wrong even though it had been accepted as the correct answer. I have now fixed it.

I had misread the question to want to change the navigation bar or that it worked differently in Android at that time.

I think at least this is a much better answer and should be better help to change the color of the navigationbar in Android and iOS.

Add this code to your Xamarin.Forms project

public interface IStatusBarPlatformSpecific
{
  void SetStatusBarColor(Color color);
}

add this class to your Android project

[assembly: Dependency(typeof(MyDemo.Droid.CustomRenderers.Statusbar))]
namespace MyDemo.Droid.CustomRenderers
{
    public class Statusbar : IStatusBarPlatformSpecific
    {
       public Statusbar()
       {
       }

       public void SetStatusBarColor(Color color)
       {
         // The SetStatusBarcolor is new since API 21
         if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
        {
          var androidColor = color.AddLuminosity(-0.1).ToAndroid();
         //Just use the plugin
 CrossCurrentActivity.Current.Activity.Window.SetStatusBarColor(androidColor);
         }
         else
         {
          // Here you will just have to set your 
          // color in styles.xml file as shown below.
         }
       }
   }
}

Add this CurrentActivityPlugin to your projects

Now you can change the color in your Forms project like this

var statusbar = DependencyService.Get<IStatusBarPlatformSpecific>();
statusbar.SetStatusBarColor(Color.Green);

Note the else statement above. If you are using an older buildversion than 21 you will need to hard-code your color to the styles.xml in your Android project like this

<?xml version="1.0" encoding="utf-8" ?>
<resources>
   <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">  
      <item name="android:statusBarColor">#544054</item>  
   </style>
</resources>

For iOS its similar

add this to your Info.plist (more docs here)

<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

and add this code to your SetStatusBarColor ethod in the iOS version of the StatusBar class

UIView statusBar = UIApplication.SharedApplication.ValueForKey(
new NSString("statusBar")) as UIView;

 if (statusBar != null && statusBar.RespondsToSelector(
 new  ObjCRuntime.Selector("setBackgroundColor:")))
 {
   // change to your desired color 
   statusBar.BackgroundColor = Color.FromHex("#7f6550").ToUIColor(); 
 }

I wrote a more detailed blog post on how to set the color of the statusbar from Xamarin.Forms if somebody is interested. It does only talk about Android and iOS but should give you an idea what to do with other platforms.

Xamarin.Forms - Change StatusBar Color, I'm coming back to this answer years later to fix it because my answer had been wrong even though it had been accepted as the correct answer� In this article, I’m going to show you how to change the Status Bar background color and status bar icon color in Xamarin Forms. In App page we can set NavigationPage property. BarBackgroundColor and BarTextColor. public App () { MainPage = new NavigationPage (new MainPage ()) { BarBackgroundColor = Color.FromHex ("#ff9999"), BarTextColor = Color.White, }; }

I believe you would be better off writing a little bit of platform-specific code:

For Android:

On your MainActivity.cs on the Droid project, right after

LoadApplication(new App());

of the overriden OnCreate method, add:

Window.SetStatusBarColor(Android.Graphics.Color.Argb(255, 0, 0, 0));

Like so:

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.SetStatusBarColor(Android.Graphics.Color.Argb(255, 0, 0, 0)); //here
        }

Change the Statusbar color from Xamarin.Forms, Change the Statusbar color from Xamarin.Forms. I set out to change the top-bar- menu on a Android/iOS device and discovered that I didn't� Description of Change With the advent of the black theme on iOS and generally good opportunities for adjusting colors, there was a need to be able to change the color of the StatusBar on the page.

Another option for Android: change the color in the file \Resources\values\styles.xml (Android project).

<item name="colorPrimaryDark">#00FF00</item>

How can i change color for statusbar on ios(xamarin forms , I have a dark background, so id like to change the statusbar color on ios to white. I mean only text and keep transparent Thanks. The NavigationPage.SetStatusBarTextColorMode method, in the Xamarin.Forms.PlatformConfiguration.iOSSpecific namespace, controls whether the status bar text color on the NavigationPage is adjusted to match the luminosity of the navigation bar, with the StatusBarTextColorMode enumeration providing two possible values:

Using this approach you can change it on every page.

Application.Current.MainPage.SetValue(NavigationPage.BarBackgroundColorProperty, Color.Black);

Controlling iOS StatusBar in Xamarin.Forms, One of the common request from designers is to be able to have a transparent NavigationBar and StatusBar and control the StatusBar text color :. Change StatusBar Color [Xamarin.Forms] Lucio. Jul 4 '18 ・1 min read. Normalmente cuando estamos desarrollando una aplicación buscamos como poder brindar una UI

Maybe I'm not understanding the question, but I hope this helps.

After searching around quite a bit trying to find out how to change the iPhoneX status bar color (the bit behind the notch), I found out that it automatically sets itself based on the BackroundColorproperty of the root ContentPage.

So in Xaml it's as easy as this:

   <ContentPage.BackgroundColor>
        <OnPlatform x:TypeArguments="Color"
                    iOS="Navy"
                    Android="Yellow"
                    />
    </ContentPage.BackgroundColor>

I'm basically using the approach described in one of the answers here: https://stackoverflow.com/a/46199029/960691, but modifying it a little by giving you a code snippet that I've focused for your individual question (at least I think!)

How To Change Status Bar Color in Xamarin Forms – Chetan Rawat, Change status bar color in Andriod. There are two ways of changing the StatusBar color, First one using Themes and second one Programatically� On iOS statusbar color depends on the Color of Navigationbar so MainPage = new NavigationPage(new MyPage()) { BarBackgroundColor = Color.FromHex("000000"), BarTextColor = Color.White }; would make a black navbar and satusbar with white text in the navbar.

Change the iOS Status Bar color in Xamarin.Forms, Change the iOS Status Bar color in Xamarin.Forms. 27 Dec 2016. Xamarin.Forms is a great way to abstract the local implementation. But, you know, sometimes� In iOS the status bar background colour by default matching the colour of the navigation bar. In other words, we don’t have to explicitly set the background colour of the status bar if we want it to match the background colour of the navigation bar.

[Enhancement] Set StatusBar color for iOS and Android from any , private void Forms_ViewInitialized(object sender, Xamarin.Forms. Set StatusBar color and StatusBarStyle for iOS Android and UWP from Page #8298 I, for example, need to change the bar-color in a ContentPage inside� Modern apps will set the status bar to match the background color when toggling between light and dark. Since we are allowing the user to set the theme, we must also set the color of the status bar. This can be accomplished with the following code: public void SetStatusBarColor(System.Drawing.Color color, bool darkStatusBarTint) { if (Build.

Setting Android Status Bar Background & Icon Colors, and tricks to dynamically change the status bar color on your Android Phillpotts we came up with a very nice theme changer for Xamarin. In this video i will show you how to change status bar color in mobile using Xamarin forms.

Comments
  • You will have to use platform-specific code for this. See a recent answer I wrote with regards to how to change the color on WP8.1.
  • Android: Window.SetStatusBarColor(Android.Graphics.Color.ParseColor("#FFFFFF")); //or any other hex value in MainActivity. On iOS statusbar color depends on the Color of Navigationbar so MainPage = new NavigationPage(new MyPage()) { BarBackgroundColor = Color.FromHex("000000"), BarTextColor = Color.White }; would make a black navbar and satusbar with white text in the navbar. To change the textcolor in statusbar you've to set <key>UIStatusBarStyle</key> <string>UIStatusBarStyleBlackTranslucent</string> in info.plist
  • UIStatusBarStyleBlackTranslucent means white text
  • var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView(); where the StatusBar-Class has BackgroundColor, BackgroundOpacity, ForegroundColor properties
  • statusBar.BackgroundOpacity = 1; is important else it wont work
  • I'm trying option 1 and it does not work for me. The color remains the same default blue.
  • Tried option 2 but my status bar is stuck as blue.
  • AFAIK, only has effect if you are using NavigationBar. When NavigationBar=false, this has no effect (in my situation).
  • What if you don't use a NavigationPage nor a NavigationBar? I
  • This is for the navigation bar, not the status bar, which is what the question is asking so I am surprised to see it marked as the accepted answer... but to pile on for NavigationBar... the easiest non-platform specific way is to just set an implicit style in your App.xaml: <Style TargetType="{x:Type NavigationPage}"> <Setter Property="BarBackgroundColor" Value="Black" /> <Setter Property="BarTextColor" Value="White" /> </Style>
  • This is the correct answer. The rest require changing the color of the navigation bar - Sometimes there is no navigation bar. Note SetStatusBarColor is only supported in API level 21 and up. Therefore, we should check for this before calling SetStatusBarColor. if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop){Window.SetStatusBarColor(...);}
  • Thank you beautiful strangers this has been vexing me
  • This is the only way to set the colour of the status bar in Android. In my experience, there is no way to do this in a cross platform manner in Xamarin Forms. I'd be happy to be proven wrong.
  • NOTE: (on iOS) if you have set HasNavigationBar=false, then this has no effect, at least in the situation I am testing.
  • This worked for me, when using iOS 11 safe area. So, my content starts below the status bar, but the background color extends over the entire page, including outside of the safe area.