Hey,
I'm trying to achieve the following:
My app usually has a black text for the status bar, but for certain screens the App changes in a full screen version with a dark background color, so i want to change the status bar text color to white. I know that in iOS i can change the color in info.plist but i don't understand how i can only change it for these certain forms pages. I researched my problem and i know that it's also possible to change the color regarding to your NavigationBar TintColor but i don't have a NavigationBar at these pages.
Any solutions or maybe a code example how i can change the status bar text color in a CustomRenderer?
Thanks in advance!
Answers
I think it is supposed to be this, but this only seem to work on iOS
There is some toolbar behaviours override out of the box.
Please check the documentation.
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/platform-specifics/
Native Android (can override the theme in Forms)
https://docs.microsoft.com/en-us/xamarin/android/user-interface/controls/tool-bar/replacing-the-action-bar
Please follow these github features and bug the Forms team to push them through or help if possible.
https://github.com/xamarin/Xamarin.Forms/issues/1716
https://github.com/xamarin/Xamarin.Forms/issues/1719
We can achieve this using Effects in Xamarin forms.
In the shared project
public class StatusBarEffect : RoutingEffect
{
private static Color BackgroundColor;
public static void SetBackgroundColor(Color color)
{
BackgroundColor = color;
}
public static Color GetBackgroundColor()
{
return BackgroundColor;
}
Code for iOS
assembly: ResolutionGroupName("Xamarin")]
[assembly: ExportEffect(typeof(MyStatusBarEffect), "StatusBarEffect")]
namespace yournamespce
{
public class MyStatusBarEffect : PlatformEffect
{
protected override void OnAttached()
{
UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
if (statusBar.RespondsToSelector(new ObjCRuntime.Selector("setBackgroundColor:")))
{
statusBar.BackgroundColor = StatusBarEffect.GetBackgroundColor().ToUIColor();
}
}
}
you can use the statusbar effect as follows in the onappearing method:
protected override void OnAppearing()
{
base.OnAppearing();
StatusBarEffect.SetBackgroundColor(Color.Green);
this.Effects.Add(new StatusBarEffect());
}
This solution mainly depends on Jorge Ramirez post.