【问题标题】:I can't change the color of text on the Xamarin Forms Shell我无法更改 Xamarin Forms Shell 上的文本颜色
【发布时间】:2021-10-23 02:30:53
【问题描述】:

如果我在智能手机上使用深色模式,黑色会保持白色,只会变得更加饱和。黑白图像以负片显示。我尝试更改 AppShell.xaml 中的代码,但没有任何效果。

AppShell.xaml

<?xml version="1.0" encoding="UTF-8"?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms" 
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
       xmlns:local="clr-namespace:App.Views"
       Title="App"
       x:Class="App.AppShell">

    <!--
        The overall app visual hierarchy is defined here, along with navigation.
    
        https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/
    -->

    <Shell.Resources>
        <ResourceDictionary>
            <Style x:Key="BaseStyle" TargetType="Element">
                <Setter Property="Shell.BackgroundColor" Value="#0f4057" />
                <Setter Property="Shell.ForegroundColor" Value="White" />
                <Setter Property="Shell.TitleColor" Value="White" />
                <Setter Property="Shell.DisabledColor" Value="#B4FFFFFF" />
                <Setter Property="Shell.UnselectedColor" Value="#95FFFFFF" />
                <Setter Property="Shell.TabBarForegroundColor" Value="White"/>
                <Setter Property="Shell.TabBarUnselectedColor" Value="#95FFFFFF"/>
                <Setter Property="Shell.TabBarTitleColor" Value="White"/>
            </Style>
            <Style TargetType="TabBar" BasedOn="{StaticResource BaseStyle}" />
            <Style TargetType="FlyoutItem" BasedOn="{StaticResource BaseStyle}" />
        </ResourceDictionary>
    </Shell.Resources>

    <TabBar>
        <ShellContent Title="Text" Icon="icon_feed.pn" Route="Page1" ContentTemplate="{DataTemplate local:Page1}" />
        <ShellContent Title="Text" Icon="icon_feed.png" ContentTemplate="{DataTemplate local:Page2}" />
        <ShellContent Title="Text" Icon="icon_feed.png" ContentTemplate="{DataTemplate local:Page3}" />
        <ShellContent Title="Text" Icon="icon_feed.png" ContentTemplate="{DataTemplate local:Page4}" />
    </TabBar>

    <!--
        If you would like to navigate to this content you can do so by calling
        await Shell.Current.GoToAsync("//LoginPage");
    -->
    <TabBar>
        <ShellContent Route="LoginPage" ContentTemplate="{DataTemplate local:LoginPage}" />
    </TabBar>

</Shell>

【问题讨论】:

    标签: xaml xamarin xamarin.forms xamarin.android


    【解决方案1】:

    您是否查看过允许您为应用定义深色和浅色主题的主题支持。

    https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/theming/system-theme-changes

    【讨论】:

      【解决方案2】:

      您可以使用Application.Current.UserAppTheme = OSAppTheme.Dark;获取当前用户的主题,并通过绑定AppThemeBinding进行更改。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-09
        • 2019-06-15
        • 1970-01-01
        • 1970-01-01
        • 2019-12-31
        • 1970-01-01
        相关资源
        最近更新 更多