George M Ceaser Jr
George M Ceaser Jr

Reputation: 1791

Xamarin Forms Flyout menu bottom tab style

I have the following Shell Flyout menu in my application:

<?xml version="1.0" encoding="utf-8" ?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
   xmlns:views="clr-namespace:UniversalCheckInApp.Views"
   x:Class="UniversalCheckInApp.AppShell">

<Shell.FlyoutHeader>
    <StackLayout BackgroundColor="#1E1F26" Padding="4,4,4,4">
        <Label Text="Navigation" TextColor="#D0E1F9" FontAttributes="Bold" HorizontalTextAlignment="Start"
               VerticalTextAlignment="Center" FontSize="Large" Margin="4,4,4,4" />
    </StackLayout>
</Shell.FlyoutHeader>


<Shell.ItemTemplate>
    <DataTemplate>
        <StackLayout HorizontalOptions="StartAndExpand" Padding="16,0,4,0" >
            <Label Text="{Binding Title}" TextColor="#1E1F26" VerticalOptions="Center" 
                   HorizontalOptions="Start" Margin="0,0,0,0" FontSize="Medium" FontAttributes="Bold" 
                   TextDecorations="Underline"/>
        </StackLayout>
    </DataTemplate>
</Shell.ItemTemplate>

<FlyoutItem Title="Configuration" >
    <ShellContent x:Name="scNetworkConfiguration" Title="Network Configuration" >
        <views:NetworkConfiguration />
    </ShellContent>

    <ShellContent x:Name="scDataConfiguration" Title="Data Configuration">
        <views:FormFieldConfiguration />
    </ShellContent>
</FlyoutItem>

<FlyoutItem Title="Collect Data">
    <ShellContent x:Name="scCollectData" Title="Collect Data">
        <views:DataCollection />
    </ShellContent>
</FlyoutItem>


<FlyoutItem Title="About">
    <ShellContent x:Name="scAbout" Title="About">
        <views:About />
    </ShellContent>
</FlyoutItem>

It renders as follows:

Screen shot

I am trying to figure out how to change the style of the two menu options that appear at the bottom of each configuration page.

UPDATE

Based on the comment below I was able to get the flyout menu options at the bottom to look as follows:

New screen show

using this XAML

<?xml version="1.0" encoding="utf-8" ?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
   xmlns:views="clr-namespace:UniversalCheckInApp.Views"
   x:Class="UniversalCheckInApp.AppShell"
   FlyoutBackgroundColor="#D0E1F9"
   BackgroundColor="#1E1F26"
   Shell.TabBarBackgroundColor="#1E1F26"
   Shell.TabBarTitleColor="#D0E1F9"
   Shell.TabBarUnselectedColor="White">


<Shell.FlyoutHeader>
    <StackLayout BackgroundColor="#1E1F26" Padding="4,4,4,4">
        <Label Text="Navigation" TextColor="#D0E1F9" FontAttributes="Bold" HorizontalTextAlignment="Start"
           VerticalTextAlignment="Center" FontSize="Large" Margin="4,4,4,4" />
    </StackLayout>
</Shell.FlyoutHeader>


<Shell.ItemTemplate>
    <DataTemplate>
        <StackLayout HorizontalOptions="StartAndExpand" Padding="16,0,4,0" >
            <Label Text="{Binding Title}" TextColor="#1E1F26" VerticalOptions="Center" 
               HorizontalOptions="Start" Margin="0,0,0,0" FontSize="Medium" FontAttributes="Bold" 
               TextDecorations="Underline"/>
        </StackLayout>
    </DataTemplate>
</Shell.ItemTemplate>

<FlyoutItem Title="Configuration" >
    <ShellContent x:Name="scNetworkConfiguration" Title="Network Configuration" >
        <views:NetworkConfiguration />
    </ShellContent>

    <ShellContent x:Name="scDataConfiguration" Title="Data Configuration">
        <views:FormFieldConfiguration />
    </ShellContent>
</FlyoutItem>

<FlyoutItem Title="Collect Data">
    <ShellContent x:Name="scCollectData" Title="Collect Data">
        <views:DataCollection />
    </ShellContent>
</FlyoutItem>


<FlyoutItem Title="About">
    <ShellContent x:Name="scAbout" Title="About">
        <views:About />
    </ShellContent>
</FlyoutItem>

The challenge now is that I want to adjust the FontSize, FontAttributes and TextDecorations properties for the Tab Bar selected and unselected items. Any idea how to do that?

Upvotes: 0

Views: 2254

Answers (1)

Jessie Zhang -MSFT
Jessie Zhang -MSFT

Reputation: 13939

You can use Style to achieve this. You can refer to the following code:

<ShellContent Route="elephants"
                  Style="{StaticResource ElephantsShell}"
                  Title="Elephants"
                  Icon="elephant.png"
                   />  

You can define Style in the Shell.Resources

  <Shell.Resources>
    <Style x:Key="BaseStyle" 
           TargetType="Element">
        <Setter Property="Shell.BackgroundColor" 
                Value="#455A64" />
        <Setter Property="Shell.ForegroundColor" 
                Value="White" />
        <Setter Property="Shell.TitleColor" 
                Value="White" />
        <Setter Property="Shell.DisabledColor" 
                Value="#B4FFFFFF" />
        <Setter Property="Shell.UnselectedColor" 
                Value="#95FFFFFF" />
    </Style>
    <Style TargetType="ShellItem" 
           BasedOn="{StaticResource BaseStyle}" />
    <Style x:Key="DomesticShell"
           TargetType="Element" 
           BasedOn="{StaticResource BaseStyle}">
        <Setter Property="Shell.BackgroundColor" 
                Value="#039BE6" />
    </Style>
    <Style x:Key="MonkeysShell" 
           TargetType="Element"
           BasedOn="{StaticResource BaseStyle}">
        <Setter Property="Shell.BackgroundColor" 
                Value="#689F39" />
    </Style>
    <Style x:Key="ElephantsShell" 
           TargetType="Element" 
           BasedOn="{StaticResource BaseStyle}">
        <Setter Property="Shell.BackgroundColor" 
                Value="#FF00FF" />
    </Style>
    <Style x:Key="BearsShell" 
           TargetType="Element" 
           BasedOn="{StaticResource BaseStyle}">
        <Setter Property="Shell.BackgroundColor"
                Value="#546DFE" />
    </Style>
    <Style x:Key="AboutShell" 
           TargetType="Element" 
           BasedOn="{StaticResource BaseStyle}">
        <Setter Property="Shell.BackgroundColor" 
                Value="#96d1ff" />
    </Style>       
</Shell.Resources>

For more details, you can refer to the official sample https://github.com/xamarin/xamarin-forms-samples/blob/master/UserInterface/Xaminals/Xaminals/AppShell.xaml

Update:

If you want to adjust the Text properties of Tab Bar selected and unselected items(e.g. normal TextColor and unselected text color), you can use the following code:

       <Setter Property="Shell.TabBarBackgroundColor"
        Value="#3498DB" />
       <Setter Property="Shell.TabBarTitleColor"
              Value="White" />
       <Setter Property="Shell.TabBarUnselectedColor"
              Value="#90EE90" />

The TabBarTitleColor is the color for selected color, the `TabBarUnselectedColor is the color for other tab unselected.

If you dont want to changes the overall Shell stlye (i.e. the background / foreground color of the bar at the top that holds that hamburger menu, you can just remove the following code:

    <Setter Property="Shell.BackgroundColor" 
            Value="#455A64" />
    <Setter Property="Shell.ForegroundColor" 
            Value="White" />

So the BaseStyle is like this:

      <Style x:Key="BaseStyle" 
           TargetType="Element">
        <Setter Property="Shell.TitleColor" 
                Value="Red" />
        <Setter Property="Shell.DisabledColor" 
                Value="#B4FFFFFF" />
        <Setter Property="Shell.UnselectedColor" 
                Value="Green" />
       <Setter Property="Shell.TabBarBackgroundColor"
        Value="#3498DB" />
       <Setter Property="Shell.TabBarTitleColor"
              Value="White" />
       <Setter Property="Shell.TabBarUnselectedColor"
              Value="#90EE90" />
     </Style>

Upvotes: 1

Related Questions