android - Xamarin 应用程序在开启暗模式的 Android 设备上自动切换到暗模式
问题描述
在启用深色主题的 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 的解决方案:
在MainActivity.cs
, beforebase.OnCreate()
中,添加以下行:
AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo;
推荐阅读
- javascript - 查找小数时,使用 .includes() 输入 type="number" 为 false
- java - 在 Spring Boot 应用程序中为 Datadog 配置跟踪
- javascript - 从 Javascript 代码中删除鼠标控件
- reactjs - 如何使用 Google API 只让城镇和地址出现在搜索下拉列表中?
- python - 如何在maya python或mel的导出文件中将变换坐标(如移动到游戏导出器中的原点)归零?
- mysql - 如何在我的 SQL 表中找到总销售额?
- github - Github API 令牌在 Github 页面中的使用
- twilio - Twilio SMS 到多个国家
- amazon-web-services - AWS API Gateway - 通过公司代理发送请求
- c++ - 在 Eclipse 中调试 C - “找不到源文件”