【问题标题】:How to set backgroundcolor of more button with other tabs [Xamarin Forms]?如何使用其他选项卡 [Xamarin Forms] 设置更多按钮的背景颜色?
【发布时间】:2022-06-22 10:34:18
【问题描述】:

我正在使用 Xamarin.Forms.Shell 开发一个用于布局和导航的应用程序。当我在 TabBar 中使用更多的五个选项卡时,自然会出现更多按钮,即每个平台(Android 和 iOS)的原生。但是,同样在 xaml 中为 Shell.Background 和 Shell.TabBarBackground 使用自定义颜色,不适用于更多按钮的选项卡背景。

我在 Xaml APP SHELL 中的代码:

 <Shell.Resources>
    <ResourceDictionary>
        <Style x:Key="BaseStyle"  TargetType="Element">
            <Setter Property="Shell.BackgroundColor" 
                    Value="{x:Static core:Colors.Background}" />
            <Setter Property="Shell.ForegroundColor" 
                    Value="White" />
            <Setter Property="Shell.TabBarBackgroundColor"
                    Value="{x:Static core:Colors.Background}" />
            <Setter Property="Shell.TabBarTitleColor"
                    Value="{x:Static core:Colors.Selection}" />
            <Setter Property="Shell.TabBarUnselectedColor"
                    Value="White" />
        </Style>
    </ResourceDictionary>
</Shell.Resources>

<ShellItem Route="Home">
    <ShellContent ContentTemplate="{DataTemplate core:HomePage}"/>
</ShellItem>

<TabBar Route="Tabs" Style="{x:StaticResource BaseStyle}">
    <Tab Route="TabSearch"
         Icon="ic_list_white"
         Title="Search">
        <ShellContent ContentTemplate="{DataTemplate core:SearchPage}"/>
    </Tab>
    <Tab
        Icon="ic_filter_list_white"
        Title="Filter">
        <ShellContent ContentTemplate="{DataTemplate core:FilterPage}"/>
    </Tab>
    
    <Tab Icon="ic_star_white"
        Title="Favourites">
        <ShellContent ContentTemplate="{DataTemplate core:FavouritesPage}"/>
    </Tab>
    
    <Tab Icon="ic_remove_red_eye_white"
        Title="Seen">
        <ShellContent ContentTemplate="{DataTemplate core:SeenPage}"/>
    </Tab>

    <Tab Icon="ic_shopping_cart_white" Title="{x:Static resources:Strings.MAINPAGE_MENU_PURCHASE_PACKAGES}">
        <ShellContent ContentTemplate="{DataTemplate core:PackagePurchasePage}"/>
    </Tab>

    <Tab Icon="ic_sync_white" Title="{x:Static resources:Strings.MAINPAGE_MENU_RESTORE_PURCHASES}"  >
        <ShellContent ContentTemplate="{DataTemplate core:RestorePurchasePage}"/>
    </Tab>

    <Tab Icon="ic_settings_white" Title="{x:Static resources:Strings.MAINPAGE_MENU_SETTINGS}"  >
        <ShellContent ContentTemplate="{DataTemplate core:SettingsPage}"/>
    </Tab>

    <Tab Icon="ic_help_white" Title="{x:Static resources:Strings.MAINPAGE_MENU_ABOUT}" >
        <ShellContent ContentTemplate="{DataTemplate views:AboutShell }"/>
    </Tab>
</TabBar>

这是我应用样式的标签栏:

当我点击更多按钮时:

我需要在这个更多按钮的屏幕上应用与我的 TabBar 上出现的相同的样式。

【问题讨论】:

    标签: android ios xamarin.forms mobile xamarin.forms.shell


    【解决方案1】:

    您可以为TabBarUnselectedColor 属性设置颜色。

     <Shell.Resources>
        <ResourceDictionary>
            <Style x:Key="BaseStyle"  TargetType="Element">
                <Setter Property="Shell.BackgroundColor" 
                    Value="Black" />
                <Setter Property="Shell.ForegroundColor" 
                    Value="White" />
                <Setter Property="Shell.TabBarBackgroundColor"
                    Value="Green" />
                <Setter Property="Shell.TabBarTitleColor"
                    Value="Red" />
                <Setter Property="Shell.TabBarUnselectedColor"
                    Value="Red" />
            </Style>
        </ResourceDictionary>
    </Shell.Resources>
    

    【讨论】:

      猜你喜欢
      • 2020-03-26
      • 1970-01-01
      • 2020-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-01
      • 2015-08-31
      • 2019-04-13
      相关资源
      最近更新 更多