Reputation: 1211
How to change background color of toolbaritems from code behind.
<ContentPage.ToolbarItems Name="ToolBarItems" BackgroundColor="#1FBED6">
<ToolbarItem Name="Menu1" Order="Secondary" Text="Test1"/>
<ToolbarItem Name="Menu2" Order="Secondary" Text="Test2"/>
<ToolbarItem Order="Primary" Icon="Cart.png"/>
</ContentPage.ToolbarItems>
Upvotes: 1
Views: 6143
Reputation: 11105
You will either need to do platform specific code or you can use the more general approach of using the NavigationPage
methods.
So if you are using a NavigationPage
, then you can do something like this:
NavigationPage navPage = new NavigationPage {
BarBackgroundColor = Color.FromHex("#1FBED6"),
BarTextColor = Color.FromHex("#000000")
}
If you wanted to make the BarBackgroundColor
change when visiting a different page, then you would just keep a global reference to the NavigationPage
. I keep it in the App.cs
class.
If you would rather go with a native approach, on iOS you could use the Appearance API and just add the styles to your AppDelegate.cs file, more info here.
Then on Android, you would want to mess around with the theme, more info on that here.
Upvotes: 1