You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MAUI中Android平台TabbedPage.BarItemColor与BarSelectedItemColor设置咨询

MAUI中TabbedPage栏项颜色的设置方法

在MAUI里,原Xamarin.Forms的android:TabbedPage.BarItemColor和BarSelectedItemColor并没有被移除,而是调整了平台特定属性的命名规范,同时也提供了更通用的设置方式,具体有以下两种实现途径:

1. 使用MAUI Android平台特定附加属性

需要先引入MAUI的Android特定命名空间,然后使用调整后的属性名:

<TabbedPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:android="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;assembly=Microsoft.Maui.Controls"
            android:TabbedPage.BarItemColor="#66FFFFFF"
            android:TabbedPage.BarSelectedItemColor="White">
    <!-- 你的子页面内容 -->
</TabbedPage>

如果是代码后台设置,可通过平台扩展方法实现:

using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;

// 假设tabbedPage是你的TabbedPage实例
tabbedPage.On<Android>().SetBarItemColor(Color.FromHex("#66FFFFFF"));
tabbedPage.On<Android>().SetBarSelectedItemColor(Colors.White);

2. 使用Shell TabBar(MAUI推荐方案)

如果你的项目采用MAUI Shell架构,直接通过TabBar的通用属性设置即可,无需平台特定命名空间,这种方式更简洁且跨平台兼容:

<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
    <TabBar UnselectedColor="#66FFFFFF" SelectedColor="White">
        <Tab Title="首页">
            <ShellContent ContentTemplate="{DataTemplate local:MainPage}" />
        </Tab>
        <Tab Title="设置">
            <ShellContent ContentTemplate="{DataTemplate local:SettingsPage}" />
        </Tab>
    </TabBar>
</Shell>

内容的提问来源于stack exchange,提问作者Emil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 00:32:07