Mvvmcross Xamarin 表单导航页面样式不起作用

Mvvmcross Xamarin Forms Navigation page style not working

我正在尝试使用 Mvvmcross 在 xamarin 表单应用程序上设置导航页面的样式。

在"adding"mmvcross之前我在App.xaml中定义了样式如下。

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

它奏效了。我得到了我定义的背景颜色和文本颜色。然后我们 "moved" 到 Mvvmcross - 我们添加了所有需要的后端代码,将所有页面从 ContentPage 更改为 MvxContentPage 等等......导航页面的背景颜色在 Android 上停止工作(我还没有试过 iOS)。如果我在 App.xaml 中更改 BarTextColor 更改应用,颜色会更改。如果我更改 BackgroundColor 它也有效 - 所有应用程序背景颜色都已更改。但无论我对 BarBackgroundColor 应用什么值,它仍然是白色的。

我的App.xaml如下:

<?xml version="1.0" encoding="utf-8" ?>
<core:MvxFormsApplication xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:views="clr-namespace:MvvmCross.Forms.Views;assembly=MvvmCross.Forms"
             xmlns:viewModels="clr-namespace:MvvmCross.ViewModels;assembly=MvvmCross"
             xmlns:core="clr-namespace:MvvmCross.Forms.Core;assembly=MvvmCross.Forms"
             xmlns:attributes="clr-namespace:MvvmCross.Forms.Presenters.Attributes;assembly=MvvmCross.Forms"
             x:Class="ShowMeTheLogs.Core.FormsApp">
    <core:MvxFormsApplication.Resources>
        <!--Global Styles-->
        <Color x:Key="ColorPrimary">#98C340</Color>
        <Color x:Key="ColorError">#CF1212</Color>
        <Color x:Key="ColorWarning">#E4AD17</Color>
        <Color x:Key="ColorInfo">#1283CF</Color>
        <Color x:Key="ColorDebug">#989898</Color>
        <Style TargetType="NavigationPage">
            <Setter Property="BarBackgroundColor" Value="{StaticResource ColorPrimary}" />
            <Setter Property="BarTextColor" Value="White" />
        </Style>

        <Style x:Key="SubmitButton" TargetType="Button">
            <Setter Property="BackgroundColor" Value="{StaticResource ColorPrimary}" />
            <Setter Property="TextColor" Value="White" />
        </Style>

        <Style x:Key="circleButton" TargetType="Button">
            <Setter Property="BackgroundColor" Value="{StaticResource ColorPrimary}" />
            <Setter Property="BorderRadius" Value="50" />
            <Setter Property="WidthRequest" Value="100" />
            <Setter Property="HeightRequest" Value="100" />
            <Setter Property="TextColor" Value="White" />
            <Setter Property="FontSize" Value="50" />
        </Style>

        <Style x:Key="smallSquareButton" TargetType="Button">
            <Setter Property="BackgroundColor" Value="{StaticResource ColorPrimary}" />
            <Setter Property="WidthRequest" Value="100" />
            <Setter Property="HeightRequest" Value="100" />
            <Setter Property="TextColor" Value="White" />
            <Setter Property="FontSize" Value="Micro" />
            <Setter Property="HorizontalOptions" Value="Center" />
            <Setter Property="VerticalOptions" Value="Center" />
        </Style>
    </core:MvxFormsApplication.Resources>
</core:MvxFormsApplication>

我的App.xalm.cs是最简单的:

public partial class FormsApp: MvxFormsApplication
    {
        public App()
        {
            InitializeComponent();
        }
    }

和最简单的视图:

<?xml version="1.0" encoding="utf-8" ?>
<views:MvxContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:views="clr-namespace:MvvmCross.Forms.Views;assembly=MvvmCross.Forms"
             x:TypeArguments="viewModels:WebAppListViewModel"
             x:Class="ShowMeTheLogs.Core.Views.WebAppListPage"
             xmlns:bindings="clr-namespace:MvvmCross.Forms.Bindings;assembly=MvvmCross.Forms"
             xmlns:viewModels="clr-namespace:ShowMeTheLogs.Core.ViewModels;assembly=ShowMeTheLogs.Core"
             Title="Sample title"
             NavigationPage.HasBackButton="False">
    <ContentPage.ToolbarItems>
        <ToolbarItem x:Name="AddNewApp" Order="Secondary" Text="Dodaj aplikację" Priority="0" Command="{bindings:MvxBind NewWebAppCommand}"/>
    </ContentPage.ToolbarItems>

    <RelativeLayout Padding="0" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
       <Non relevant="Code" />
    </RelativeLayout>

</views:MvxContentPage>

我完全不知道为什么它不起作用。 android 代码的唯一变化是将 class RootActivity: CompatActivity 更改为 class RootActivity: MvxFormsAppCompatActivity

以前有人解决过这个问题吗? 软件包是从 NuGet 获得的 - MvvmCross(和 MvvmCross.Forms)版本 6.2.2 - Xamarin 版本 28.0.0 - Xamarin.Forms 版本 3.4.0

在您的 MainActivity OnCreate 方法中,确保设置工具栏资源的两行 base.OnCreate() 调用之前:

protected override void OnCreate(Bundle bundle)
{
    TabLayoutResource = Resource.Layout.Tabbar;
    ToolbarResource = Resource.Layout.Toolbar;
    base.OnCreate(bundle);
}

https://github.com/MvvmCross/MvvmCross/issues/2301