微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Xamarin Form iOS 实现中导航栏中的文本颜色不正确

如何解决Xamarin Form iOS 实现中导航栏中的文本颜色不正确

我确实有在 Xamarin Forms 中制作的 Android 和 iOS 应用程序。 在 android 实现中,一切都按预期进行。

我的 AppShell.xaml 中有以下代码

<Shell.Resources>
    <ResourceDictionary>
        <Style x:Key="BaseStyle" targettype="Element">
            <Setter Property="Shell.BackgroundColor" Value="{StaticResource Primary}" />
            <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 Primary}" />
            <Setter Property="Shell.TabBarForegroundColor" Value="White"/>
            <Setter Property="Shell.TabBarUnselectedColor" Value="#95FFFFFF"/>
            <Setter Property="Shell.TabBarTitleColor" Value="White"/>
        </Style>
        <Style targettype="TabBar" BasedOn="{StaticResource BaseStyle}" />
        <Style targettype="FlyoutItem" BasedOn="{StaticResource BaseStyle}" />

        <!--
        Default Styles for all Flyout Items
        https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/flyout#flyoutitem-and-menuitem-style-classes
        -->
        <Style Class="FlyoutItemLabelStyle" targettype="Label">
            <Setter Property="TextColor" Value="{StaticResource Primary}"></Setter>
        </Style>
        <Style Class="FlyoutItemLayoutStyle" targettype="Layout" ApplyToDerivedTypes="True">
            <Setter Property="BackgroundColor" Value="LightBlue"></Setter>
            <Setter Property="visualstatemanager.VisualStateGroups">
                <VisualStateGroupList>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="normal">
                            <VisualState.Setters>
                                <Setter Property="BackgroundColor" Value="{StaticResource Primary}" />
                                <Setter TargetName="FlyoutItemLabel" Property="Label.TextColor" Value="White" />
                            </VisualState.Setters>
                        </VisualState>
                        <VisualState x:Name="Selected">
                            <VisualState.Setters>
                                <Setter Property="BackgroundColor" Value="White" />
                            </VisualState.Setters>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateGroupList>
            </Setter>
        </Style>

        <!--
        Custom Style you can apply to any Flyout Item
        -->
        <Style Class="MenuItemLayoutStyle" targettype="Layout" ApplyToDerivedTypes="True">
            <Setter Property="visualstatemanager.VisualStateGroups">
                <VisualStateGroupList>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="normal">
                            <VisualState.Setters>
                                <Setter TargetName="FlyoutItemLabel" Property="Label.TextColor" Value="White" />
                            </VisualState.Setters>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateGroupList>
            </Setter>
        </Style>
    </ResourceDictionary>
</Shell.Resources>

但我的问题是,iOS 中的颜色似乎不正确。这是对比图

enter image description here

您可以看到导航返回按钮为蓝色颜色,导航标题黑色,输入框说明为蓝色。在Android上,它是红色或白色。

感谢您的帮助。

解决方法

尝试删除

            <Setter Property="Shell.ForegroundColor" Value="White" />
            <Setter Property="Shell.TitleColor" Value="White" />

来自 <ResourceDictionary> 并将它们添加到 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:local="clr-namespace:TestShell.Views"
       Title="TestShell"
       ForegroundColor="White"
       TitleColor="White"       
       x:Class="TestShell.AppShell">

    <Shell.Resources>
        <ResourceDictionary>
            <Style x:Key="BaseStyle" TargetType="Element">
                <Setter Property="Shell.BackgroundColor" Value="{StaticResource Primary}" />
                <Setter Property="Shell.DisabledColor" Value="#B4FFFFFF" />
                <Setter Property="Shell.UnselectedColor" Value="#95FFFFFF" />
                <Setter Property="Shell.TabBarBackgroundColor" Value="{StaticResource Primary}" />
                <Setter Property="Shell.TabBarForegroundColor" Value="White"/>
                <Setter Property="Shell.TabBarUnselectedColor" Value="#95FFFFFF"/>
                <Setter Property="Shell.TabBarTitleColor" Value="White"/>
            </Style>
            <Style TargetType="TabBar" BasedOn="{StaticResource BaseStyle}" />
            <Style TargetType="FlyoutItem" BasedOn="{StaticResource BaseStyle}" />

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。