Xamarin Forms Flyout 菜单底部选项卡样式
Xamarin Forms Flyout menu bottom tab style
我的应用程序中有以下 Shell 弹出菜单:
<?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>
渲染如下:
我正在研究如何更改出现在每个配置页面底部的两个菜单选项的样式。
更新
根据下面的评论,我得到了底部的弹出式菜单选项,如下所示:
使用这个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>
现在的挑战是我想调整选项卡栏选中和未选中项的 FontSize、FontAttributes 和 TextDecorations 属性。知道怎么做吗?
您可以使用 Style
来实现。
您可以参考以下代码:
<ShellContent Route="elephants"
Style="{StaticResource ElephantsShell}"
Title="Elephants"
Icon="elephant.png"
/>
您可以在 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>
更多细节可以参考官方示例https://github.com/xamarin/xamarin-forms-samples/blob/master/UserInterface/Xaminals/Xaminals/AppShell.xaml
更新:
如果要调整Tab Bar选中项和未选中项的Text属性(例如普通TextColor和未选中文本颜色),可以使用以下代码:
<Setter Property="Shell.TabBarBackgroundColor"
Value="#3498DB" />
<Setter Property="Shell.TabBarTitleColor"
Value="White" />
<Setter Property="Shell.TabBarUnselectedColor"
Value="#90EE90" />
TabBarTitleColor
为选中颜色,`TabBarUnselectedColor为其他未选中标签的颜色。
如果您不想更改整体 Shell stlye(即顶部包含汉堡菜单的栏的背景/前景色,您可以删除以下代码:
<Setter Property="Shell.BackgroundColor"
Value="#455A64" />
<Setter Property="Shell.ForegroundColor"
Value="White" />
所以BaseStyle
是这样的:
<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>
我的应用程序中有以下 Shell 弹出菜单:
<?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>
渲染如下:
我正在研究如何更改出现在每个配置页面底部的两个菜单选项的样式。
更新
根据下面的评论,我得到了底部的弹出式菜单选项,如下所示:
使用这个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>
现在的挑战是我想调整选项卡栏选中和未选中项的 FontSize、FontAttributes 和 TextDecorations 属性。知道怎么做吗?
您可以使用 Style
来实现。
您可以参考以下代码:
<ShellContent Route="elephants"
Style="{StaticResource ElephantsShell}"
Title="Elephants"
Icon="elephant.png"
/>
您可以在 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>
更多细节可以参考官方示例https://github.com/xamarin/xamarin-forms-samples/blob/master/UserInterface/Xaminals/Xaminals/AppShell.xaml
更新:
如果要调整Tab Bar选中项和未选中项的Text属性(例如普通TextColor和未选中文本颜色),可以使用以下代码:
<Setter Property="Shell.TabBarBackgroundColor"
Value="#3498DB" />
<Setter Property="Shell.TabBarTitleColor"
Value="White" />
<Setter Property="Shell.TabBarUnselectedColor"
Value="#90EE90" />
TabBarTitleColor
为选中颜色,`TabBarUnselectedColor为其他未选中标签的颜色。
如果您不想更改整体 Shell stlye(即顶部包含汉堡菜单的栏的背景/前景色,您可以删除以下代码:
<Setter Property="Shell.BackgroundColor"
Value="#455A64" />
<Setter Property="Shell.ForegroundColor"
Value="White" />
所以BaseStyle
是这样的:
<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>