2
votes

Hy, I'm new in Xamarin Forms and I'm working with BottomBarPage, now I need a custom Toolbar with different items, as you can see in the code I added a ToolbarItem succesfully, my doubt is, how can I change the Toolbar background color? I tryed with x:BackgroundColor in xf:BottomBarPage but didn't work. Any suggestion?

<?xml version="1.0" encoding="utf-8" ?>
<xf:BottomBarPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            x:Class="MyProject.Views.StartPage"
            xmlns:xf="clr-namespace:BottomBar.XamarinForms;assembly=BottomBar.XamarinForms"
            xmlns:Views="clr-namespace:MyProject.Views;assembly=MyProject"
            x:Name="TabMenu">


    <xf:BottomBarPage.ToolbarItems x:BackgroundColor="#D60000">
        <ToolbarItem Name="User" Order="Primary" Icon="home.png" Text="Item 1" Priority="0" Clicked="User_Clicked"/>
        <!--<ToolbarItem Name="MenuItem2" Order="Primary" Icon="Xamarin.png" Text="Item 2" Priority="1" />-->
    </xf:BottomBarPage.ToolbarItems>

    <xf:BottomBarPage.Children>
        <Views:MainPage 
            ClassId="Home"
            Title="Page1" 
            Icon="Page1.png" 
            xf:BottomBarPageExtensions.TabColor="#D60000"/>
        <Views:MainPage 
            Title="Page2" 
            Icon="Page2.png"  
            xf:BottomBarPageExtensions.TabColor="#D60000"/>
        <Views:Graphs 
            Title="Page3"  
            Icon="Page3.png" 
            xf:BottomBarPageExtensions.TabColor="#D60000"/>
        <Views:MainPage 
            Title="Page4" 
            Icon="Page4.png"
            xf:BottomBarPageExtensions.TabColor="#D60000"/>
        <Views:Info 
            Title="Page5" 
            Icon="Page5.png"
            xf:BottomBarPageExtensions.TabColor="#D60000"/>
    </xf:BottomBarPage.Children>
</xf:BottomBarPage>

The blue bar is the background color which I want to change Color ToolBar

Now with using a TabbedPage, the declaration is: Tabbed Page

But the color of the bar at the top still being blue, how can I change it? Top ToolBar

3
Seems you're using a library that is outdated, you can do that now on XF, follow this article: Official Bottom Navigation/Bottom Tabs on AndroidFabriBertani
@FabriBertani I'm doing it cross-platform iOS&Androidnotarealgreal

3 Answers

2
votes

As @fabriBertani said , use the official TabbedPage with bottom tabs specification as described in the article he shared check the code i shared below

<TabbedPage
    xmlns ="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:test="clr-namespace:Test;assembly=Test"
    xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
    android:TabbedPage.ToolbarPlacement="Bottom" 
    BarBackgroundColor="Red"
    x:Class="Test.TabbedPage">
    <test:MainPage Title="Page 1" Icon="alarm"/>
    <test:MainPage Title="Page 2" Icon="watch"/>
</TabbedPage>

So now you have a Tabbar in the buttom with the color red .

Now you need to change the color of the NavigationBar to do this you need to access the NavigationPage and change the bar color. If you want to set it once then I would change that in the App.cs as below :

   public App()
        {
            InitializeComponent();

            MainPage = new NavigationPage(new MainPage())
            {
                BarBackgroundColor = Color.Red
            };
        }
1
votes

Go to your App.xaml.cs After Initialize component in Main Page

MainPage = new NavigationPage(new Login())
{
    BarBackgroundColor = Color.DarkOrange
};

This will Change your ToolBarItem Background Color.Simple!!

0
votes

Considering the tabs @FabriBertani gave you the answer, nothing to add to that.

Considering the toolbar, Xamarin.Forms don't have the support for iOS toolbar and if you want to write something exactly like that you'll probably have to do a lot of work yourself and it is a better idea to use Xamarin.iOS + Xamarin.Android in that case.

If you want Xamari.Forms there is no easy solution, requires a high skill level and a lot of time so there can hardly be a better answer - no one will do it for you and I am not sure whether your skills match the required level and even if they do it is probably a waste of time to put effort in something like this instead of using alternative approaches.