【发布时间】:2020-11-09 16:53:45
【问题描述】:
在启用深色主题的 Android 手机上,我的 Xamarin.Forms 应用程序(Shell 项目)会自动切换到深色主题。我不希望这种情况发生。我尝试了多种方法来禁用它,但都没有奏效。 知道有什么问题吗?
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:retrogamez="clr-namespace:RetroGameZ"
Title="RetroGameZ"
x:Class="RetroGameZ.AppShell">
<Shell.Resources>
<ResourceDictionary>
<Style x:Key="BaseStyle" TargetType="Element">
<Setter Property="Shell.BackgroundColor" Value="#049DBF" />
<Setter Property="Shell.ForegroundColor" Value="White" />
<Setter Property="Shell.TitleColor" Value="White" />
<Setter Property="Shell.DisabledColor" Value="#03A6A6" />
<Setter Property="Shell.UnselectedColor" Value="#D3D3D3" />
<Setter Property="Shell.TabBarBackgroundColor" Value="#049DBF" />
<Setter Property="Shell.TabBarForegroundColor" Value="White"/>
<Setter Property="Shell.TabBarUnselectedColor" Value="#D3D3D3"/>
<Setter Property="Shell.TabBarTitleColor" Value="White"/>
</Style>
<Style TargetType="TabBar" BasedOn="{StaticResource BaseStyle}" />
<Style TargetType="FlyoutItem" BasedOn="{StaticResource BaseStyle}" />
</ResourceDictionary>
</Shell.Resources>
后来只有单独的组件。
【问题讨论】:
-
我相信欢迎更多的上下文和细节,以便其他人能够轻松地帮助您。你检查过devblogs.microsoft.com/xamarin/app-themes-xamarin-forms 吗?
-
我只能看到您正在静态设置颜色而不是使用
{AppThemeBinding Dark=..., Light=...}" -
您的项目中还有其他暗模式设置吗?你们是如何支持暗模式的?如果没有深色模式设置,您的应用将不会切换到深色主题,因为深色主题和浅色主题之间没有区别。
标签: android xamarin xamarin.forms xamarin.android android-darkmode