【问题标题】:get rid of default blue in Xamarin forms摆脱 Xamarin 表单中的默认蓝色
【发布时间】:2022-01-24 20:23:36
【问题描述】:

我有一个 Xamarin 表单项目,我不知道如何摆脱背景中的默认蓝色。我在 app.xaml 中更改了资源字典中的原色。它在各个页面上运行良好,但它们在背景中仍然有些蓝色(请参阅随附的屏幕截图),我也需要更改。 提前致谢

    <Application.Resources>
    <ResourceDictionary>
        <Color x:Key="Primary">BurlyWood</Color>
        <Style TargetType="Button">
            <Setter Property="BorderRadius" Value="15"/>
            <Setter Property="BorderWidth" Value="2"/>
            <Setter Property="BorderColor" Value="{StaticResource Primary}"/>
            <Setter Property="TextColor" Value="{StaticResource Primary}"></Setter>
            <Setter Property="VisualStateManager.VisualStateGroups">
                <VisualStateGroupList>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal">
                            <VisualState.Setters>
                                <Setter Property="BackgroundColor" Value="White" />
                            </VisualState.Setters>
                        </VisualState>
                        <VisualState x:Name="Disabled">
                            <VisualState.Setters>
                                <Setter Property="BackgroundColor" Value="#332196F3" />
                            </VisualState.Setters>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateGroupList>
            </Setter>
        </Style>
    </ResourceDictionary>        
</Application.Resources>

enter image description here

enter image description here

【问题讨论】:

    标签: xamarin.forms


    【解决方案1】:

    有两个吧。导航栏和状态栏。 对于导航栏,将此代码添加到 ResourceDictionary 标记内

    <Style TargetType="NavigationPage">
          <Setter Property="BarBackgroundColor" Value="White" />
          <Setter Property="BarTextColor" Value="Black" />
    </Style>
    

    或者,在 MainPage.xaml.cs 文件的构造函数中添加这两行

    BarBackgroundColor = Color.White;
    BarTextColor = Color.Black;
    

    对于状态栏,请遵循以下链接说明:

    安卓:Click Here

    IOS:Click Here

    【讨论】:

    • 感谢 Kaushik,它就像一个魅力,除了我无法测试 ios,但我稍后会担心。再次感谢!
    猜你喜欢
    • 2018-12-30
    • 1970-01-01
    • 2014-07-25
    • 1970-01-01
    • 2017-08-26
    • 1970-01-01
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多