标题栏不会改变颜色 [英] Title Bar will not change color

查看:91
本文介绍了标题栏不会改变颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xamrian Forms 4.0,并且出于某些奇怪的原因,即使我在colors.xml中将其设置为黑色,我的标题栏也不会显示为黑色.我正在使用新的AppShell应用程序项目是他们的问题.

I am using Xamrian forms 4.0 and for some strange reason my title bar is not showing as black even though I have set it to black in my colors.xml I am using the new AppShell application project is their an issue with this.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="launcher_background">#FFFFFF</color>
    <color name="colorPrimary">#000000</color>
    <color name="colorPrimaryDark">#000000</color>
    <color name="colorAccent">#000000</color>
</resources>

此代码在标准的Xam Forms应用程序外壳模板中.

This code is in the standard xam forms app shell template.

<Shell.Resources>
    <ResourceDictionary>
        <Color x:Key="NavigationPrimary">#2196F3</Color>
        <Style x:Key="BaseStyle" TargetType="Element">
            <Setter Property="Shell.BackgroundColor" Value="#000000" />
            <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="#000000" />
            <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}" />
    </ResourceDictionary>
</Shell.Resources>

推荐答案

更改外壳中的操作栏,它有点复杂,首先,我们可以通过在外壳中添加BackgroundColor="Green"来设置背景色. xml

Change the action bar in the shell, it has a little complicated, First of all, we could set the background color by add BackgroundColor="Green" in the shell .xml

<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:ShellActionBar.Views"
  Title="ShellActionBar"
   BackgroundColor="Green"
   x:Class="ShellActionBar.AppShell">

但是,结果类似于以下屏幕截图. TabBar的颜色已更改为绿色.

But, The result like the following screenshot. The color of TabBar was changed to green.

然后,我们应该为TabBar创建样式.为了测试,我复制了TabBar的默认样式,

Then, we should create styles for TabBar. Just for test, I copy default styles of TabBar,

  <Shell.Resources>
<ResourceDictionary>
    <Color x:Key="NavigationPrimary">#2196F3</Color>
    <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="Browse" Icon="tab_feed.png" >
    <ShellContent ContentTemplate="{DataTemplate local:ItemsPage}" />
</Tab>
<Tab Title="About" Icon="tab_about.png">
    <ShellContent ContentTemplate="{DataTemplate local:AboutPage}" />
</Tab>
</TabBar>

此处正在运行屏幕截图.

Here is running screenshot.

这篇关于标题栏不会改变颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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