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

如何修改Xamarin FlyoutPage中标题文本的颜色?

修改FlyoutPage标题文本颜色的方法
  • 直接设置内置标题栏文本颜色
    不管是Xamarin.Forms还是.NET MAUI,都可以通过NavigationPage.BarTextColor附加属性快速修改标题颜色,XAML写法:

    <FlyoutPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                x:Class="YourApp.MainFlyoutPage"
                Title="首页"
                NavigationPage.BarTextColor="#E63946"> <!-- 这里替换成你要的颜色值 -->
        <!-- 下方添加Flyout和Detail区域的内容 -->
    </FlyoutPage>
    

    代码后台设置的话,在FlyoutPage的构造函数里加:

    public MainFlyoutPage()
    {
        InitializeComponent();
        NavigationPage.SetBarTextColor(this, Color.FromHex("E63946"));
    }
    
  • 自定义TitleView实现完全控制
    如果内置样式不够用,直接自定义标题视图,可自由调整颜色、字号、布局:

    <FlyoutPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                x:Class="YourApp.MainFlyoutPage">
        <FlyoutPage.Detail>
            <NavigationPage>
                <NavigationPage.TitleView>
                    <Label Text="自定义标题" 
                           TextColor="#1D3557" 
                           FontSize="18"
                           HorizontalOptions="Center"
                           VerticalOptions="Center"/>
                </NavigationPage.TitleView>
                <!-- 你的主页内容 -->
            </NavigationPage>
        </FlyoutPage.Detail>
        <!-- 侧边菜单Flyout内容 -->
    </FlyoutPage>
    
  • 平台专属调整(按需使用)

    • Android:打开项目中的Resources/values/styles.xml,修改主题里的android:textColorPrimary属性,对应标题文本颜色;
    • iOS:在Info.plist中设置UIStatusBarStyle为UIStatusBarStyleLightContent(浅色标题),或者通过代码修改导航栏的TitleTextAttributes。

内容的提问来源于stack exchange,提问作者Aydogan İLHAN

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 03:36:29