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
)
On the latest versions of Xamarin you no longer need sketchy plugins and can instead do the following on Android:
var androidColor = color.ToAndroid();
Xamarin.Essentials.Platform.CurrentActivity.Window.SetStatusBarColor(androidColor);
So a complete dependency example in Android:
using System;
using Android.OS;
using WikiSpiv.Droid.Extras;
using WikiSpiv.Extras;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: Dependency(typeof(Statusbar))]
namespace WikiSpiv.Droid.Extras
{
public class Statusbar : IStatusBarPlatformSpecific
{
public Statusbar()
{
}
public void SetStatusBarColor(Color color)
{
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
var androidColor = color.ToAndroid();
Xamarin.Essentials.Platform.CurrentActivity.Window.SetStatusBarColor(androidColor);
}
}
}
}
In Forms:
using System;
using Xamarin.Forms;
namespace WikiSpiv.Extras
{
public interface IStatusBarPlatformSpecific
{
public void SetStatusBarColor(Color color);
}
}
And it can be called like this:
var statusbar = DependencyService.Get();
statusbar.SetStatusBarColor(Color.Green);