【问题标题】:How to set background color of selected tab in xamarin.forms for android?如何在 xamarin.forms for android 中设置选定选项卡的背景颜色?
【发布时间】:2019-01-11 00:49:36
【问题描述】:

我在 xamarin.forms 中工作。我已经在 android 中实现了底部标签页,如下面的代码

<TabbedPage 
                xmlns="http://xamarin.com/schemas/2014/forms"
                xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                x:Class="Inika.Views.BottomBar.BottomBarPages"
                xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
                BarBackgroundColor="White"
                android:TabbedPage.ToolbarPlacement="Bottom"
                android:TabbedPage.BarItemColor="#A9A9A9"
                android:TabbedPage.BarSelectedItemColor="Black">
</TabbedPage>

我正在使用 xamarin.form 3.1 的新功能,如下链接

https://blog.xamarin.com/xamarin-forms-3-1-improvments/

根据我当前的代码,我的输出如下图所示

但我想设置所选标签的背景颜色。 “BarBackgroundColor”属性设置整个Bar的颜色。我没有找到任何只在选定选项卡中设置颜色的属性。

我需要这样的输出

请建议通过自定义渲染或任何解决方法,但我不想使用任何自定义插件。

【问题讨论】:

    标签: android xamarin xamarin.forms tabbedpage


    【解决方案1】:

    这个问题已经在 SO 上得到回答。尽管如此,请尝试以下操作。

    如果你使用 FormsAppCompatActivity,你可以使用

    app:tabIndicatorColor="#FF3300" <!-- Set indicator color here, sets it to red-->
    

    编辑

    您需要创建一个自定义渲染器。

    在 github 上查看 this 示例。

    【讨论】:

    • 我想设置仅选定标签的背景颜色。根据我所需的所选选项卡的输出图像背景颜色为黑色。我试过这个属性,但没有工作。
    猜你喜欢
    • 1970-01-01
    • 2012-12-12
    • 2011-08-28
    • 1970-01-01
    • 2014-05-07
    • 2017-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多