首页 > 解决方案 > Xamarin Forms Shell 标题栏颜色在深色主题中未正确设置

问题描述

我有一个 xamarin 表单 shell 应用程序。我用这种风格设置标题栏颜色:

<Color x:Key="BackgroundColorDark">#121212</Color>
<Color x:Key="BackgroundColorLight">#EFF2F5</Color>

<Color x:Key="TextPrimaryColor_Dark">#FFFFFF</Color>
<Color x:Key="TextPrimaryColor_Light">#323130</Color>

<Style x:Key="BaseStyle"
       TargetType="Element"
       ApplyToDerivedTypes="True">
    <Setter Property="Shell.BackgroundColor"
            Value="{AppThemeBinding Dark={StaticResource BackgroundColorDark}, Light={StaticResource BackgroundColorLight}}" />
    <Setter Property="Shell.ForegroundColor"
            Value="{AppThemeBinding Dark={StaticResource TextPrimaryColor_Dark}, Light={StaticResource TextPrimaryColor_Light}}" />
    <Setter Property="Shell.DisabledColor"
            Value="#B4000000" />
    <Setter Property="Shell.UnselectedColor"
            Value="#CC0000" />
    <Setter Property="Shell.NavBarHasShadow"
            Value="false"/>
</Style>

在浅色主题中,这可以按预期工作,并且与背景相同:

在此处输入图像描述

但在深色主题中,标题栏似乎有不同的颜色: 在此处输入图像描述

因为它看起来好像标题栏是半透明的,所以我尝试使用导航页面上的 ios 特定设置显式停用它,但这不起作用。

ios:NavigationPage.IsNavigationBarTranslucent="true"

如何正确应用深色主题中的背景颜色?

Xamarin 表单版本:4.8.0.1269 源代码存储库:https ://github.com/NPadrutt/MoneyFox.Windows/tree/mobile-redesign

标签: xamarin.forms

解决方案


iOS.project中,您可以设置删除默认 alphaUINavigationBar.Appearance.Translucent = false;的 方法。FinishedLaunching

public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
    //
    // This method is invoked when the application has loaded and is ready to run. In this 
    // method you should instantiate the window, load the UI into it and then make the window
    // visible.
    //
    // You have 17 seconds to return from this method, or iOS will terminate your application.
    //
    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental");
        global::Xamarin.Forms.Forms.Init();
        LoadApplication(new App());

        UINavigationBar.Appearance.Translucent = false;

        return base.FinishedLaunching(app, options);
    }
}

推荐阅读