Is there a way I can customize the color schema of tabs on Xamarin.Forms.TabbedPage
object so it does not take the default look and feel of the target platform?
I would like to change font color, background and current selected tab color.
I suggest to use a custom renderer.
Here is an example for iOS:
[assembly: ExportRenderer(typeof(TabbedPage), typeof(TabbedPageRenderer))]
namespace MyApp.iOS
{
public class TabbedPageRenderer : TabbedRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
TabBar.TintColor = UIColor.White;
TabBar.BarTintColor = UIColor.Black;
TabBar.BackgroundColor = UIColor.Gray;
}
}
}
Just past this class in the Xamarin.iOS project.
For Xamarin.Android you could also use a custom renderer to accomplish the same. The Android implementation of the custom renderer looks different from the iOS version.
Late for the party.
Now you can change the tabbed page background color as follows
BarBackgroundColor = Color.Black;
Below links may help you more
How to change color of tabbed page indicator in Xamarin.Droid?
http://thatcsharpguy.com/post/platformtabbedpage-xamarin-forms-en/
In tabbed page , in order to change the header color in xamarin forms not in android native.
Tabbed page code:
class MainPage : TabbedPage
{
LoginManager app;
public MainPage(LoginManager ilm)
{
app = ilm;
Title = "Infrastructure";
Icon = "server.png";
this.BarTextColor = Color.White;
this.BarBackgroundColor = Color.Blue;
Children.Add(new AssetsView());
Children.Add(new ServiceView());
ToolbarItem tbi = new ToolbarItem() {
Text = "Logout",
Order = ToolbarItemOrder.Secondary,
Priority = 0,
};
AssetView Code:
public AssetView()
{
Title = "Assets";
this.BackgroundColor = Color.FromHex("D3D3D3");
list = new AssetsList();
searchbar = new SearchBar()
{
Placeholder = "Search",
TextColor = Color.Black,
BackgroundColor = Color.White,
CancelButtonColor = Color.Black,
PlaceholderColor = Color.Black
};
ServiceView Code:
public class ServiceView : ContentPage
{
ServiceList list;
SearchBar searchbar;
public ServiceView()
{
Title = "Services";
this.BackgroundColor = Color.FromHex("D3D3D3");
list = new ServiceList();
searchbar = new SearchBar()
{
Placeholder = "Search",
TextColor = Color.Black,
BackgroundColor = Color.White,
CancelButtonColor = Color.Black,
PlaceholderColor = Color.Black
};
I am able to achieve this in Android by doing the following:
Cast your Current.MainPage to a TabbedPage - this will let you set the properties.
((TabbedPage)Current.MainPage).BarBackgroundColor = Color.FromHex(settings.AppSecondaryColour);
You Should be able to change the other properties you wish in the same way. I have NOT tested this in IOS yet.
You can do it this way :
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:views="clr-namespace:SilCoyLuhn.Views"
x:Class="SilCoyLuhn.Views.MainPage"
BarBackgroundColor="{StaticResource Primary}"
BarTextColor="{StaticResource LightTextColor}">
<TabbedPage.Resources>
<ResourceDictionary>
<Color x:Key="Primary">#9DD69F</Color>
<Color x:Key="Accent">#E1F4E0</Color>
<Color x:Key="LightTextColor">#999999</Color>
</ResourceDictionary>
</TabbedPage.Resources>
</TabbedPage>
In the <TabbedPage.Resources>
, I define static ressources used as BarBackgroundColor
and BarTextColor
.