当在启用了深色主题的 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>
后来就只剩下单独的组件了。
找到了Android的解决方案:
In MainActivity.cs
, 前base.OnCreate()
,添加这一行:
AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)