ossentoo ossentoo - 2 months ago 8
C# Question

How to set BarBackgroundColor for all views?

I've got an MvvmCross Xamarin Forms application that I'm developing for iOS and Android.

I'm trying to set the

BarBackgroundColor = Color.FromHex("F26C4F")


for all views (with NavigationPage) in one common place. If i was using straight Xamarin Forms, I would perhaps have a base class inheriting from NavigationPage and then setup the stylings in the base class constructor.

However, I'm lost because with MvvmCross, a lot of the startup code is in the iOS project. All I have in the Xamarin Forms project is:

public override void Initialize()
{
CreatableTypes()
.EndingWith("Service")
.AsInterfaces()
.RegisterAsLazySingleton();

RegisterAppStart<FirstViewModel>();
}


in the App.cs class.

So, what's the best way of applying common styling (ideally to both app builds) in an MvvmCross Xamarin Forms application?

It would be handy to have a code snippet please.

thanks

Answer

You could use the UIAppearance API on iOS and Styles on Android to do this. Though it would be platform specific.

iOS:

UINavigationBar.Appearance.BarTintColor = UIColor.Blue;

Droid

<item name="android:navigationBarColor">@color/primary_white</item>