更改 Xamarin 移动应用程序的工具栏颜色 [英] Change Toolbar Color for Xamarin Mobile App

查看:32
本文介绍了更改 Xamarin 移动应用程序的工具栏颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 xamarin.forms 开发的新手,我正在使用 VisualStudio 2019 来实现相同的目标.我正在开发一个示例 shell 应用程序,但无法更改工具栏的颜色(图片中的蓝色).任何人都可以帮助我解决这个问题.

I am new to xamarin.forms development and I am using VisualStudio 2019 to achieve the same. I am developing a sample shell application but unable to change the colour of toolbar(blue color in the picture). Could anyone please help me on this issue.

推荐答案

我们可以通过在shell.xaml中添加BackgroundColor="Green"来设置背景颜色

We could set the background color by add BackgroundColor="Green" in the shell.xaml

例如我们设置它Green

<Shell 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:local="clr-namespace:xxx"
   Title="xxx"
   BackgroundColor="Green"
   x:Class="xxx.AppShell">

这将使 TabBar 的颜色同时变为绿色.所以我们应该为 TabBar 创建样式.

This will let color of TabBar been changed to green at the same time . So we should create styles for TabBar.

<Shell.Resources>
    <ResourceDictionary>
        <Color x:Key="NavigationPrimary">#2196F3</Color> //color of TabBar

        <Style x:Key="BaseStyle" TargetType="Element">
            <Setter Property="Shell.BackgroundColor" Value="{StaticResource NavigationPrimary}" />
            <Setter Property="Shell.ForegroundColor" Value="White" />
            <Setter Property="Shell.TitleColor" Value="White" />
            <Setter Property="Shell.DisabledColor" Value="#B4FFFFFF" />
            <Setter Property="Shell.UnselectedColor" Value="#95FFFFFF" />
            <Setter Property="Shell.TabBarBackgroundColor" Value="{StaticResource NavigationPrimary}" />
            <Setter Property="Shell.TabBarForegroundColor" Value="White"/>
            <Setter Property="Shell.TabBarUnselectedColor" Value="#95FFFFFF"/>
            <Setter Property="Shell.TabBarTitleColor" Value="White"/>
        </Style>
        <Style x:Key="MyBaseStyle" TargetType="Element">

            <Setter Property="Shell.ForegroundColor" Value="White" />
            <Setter Property="Shell.TitleColor" Value="White" />
            <Setter Property="Shell.DisabledColor" Value="#B4FFFFFF" />
            <Setter Property="Shell.UnselectedColor" Value="#95FFFFFF" />
            <Setter Property="Shell.TabBarBackgroundColor" Value="{StaticResource NavigationPrimary}" />
            <Setter Property="Shell.TabBarForegroundColor" Value="White"/>
            <Setter Property="Shell.TabBarUnselectedColor" Value="#95FFFFFF"/>
            <Setter Property="Shell.TabBarTitleColor" Value="White"/>
        </Style>

        <Style TargetType="ShellItem" BasedOn="{StaticResource BaseStyle}" />
        <Style TargetType="TabBar" BasedOn="{StaticResource MyBaseStyle}" />
    </ResourceDictionary>
</Shell.Resources>

<!-- Your Pages -->
<TabBar  >
    <Tab Title="xxx" Icon="xxx" >
        <ShellContent ContentTemplate="{DataTemplate xxx}" />
    </Tab>
    <Tab Title="xxx" Icon="xxx">
        <ShellContent ContentTemplate="{DataTemplate xxx}" />
    </Tab>
</TabBar>

这篇关于更改 Xamarin 移动应用程序的工具栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆