英文:
Xamarin iOS change the default icon color to white in Light Mode
问题
如何在iOS设备的浅色模式下显示深色模式图标?我已经搜索了几个月的这个问题,每篇帖子似乎都陷入了死胡同,或者解决方案根本不起作用。我正在使用Xamarin 17.3和VS 2022进行应用程序开发,同时为Android和iOS开发应用程序。我们有Shell的背景颜色(<Setter Property="Shell.BackgroundColor" Value="#141B4D"),这是一种深蓝色。默认的黑色图标(电池、时间等)在这个背景下显示不清楚(这是公司的颜色,不能更改)。Android似乎自行处理这个问题,我不需要进行任何更改,浅色和深色模式下都会显示浅色图标在深色背景上。但是在iOS的浅色模式下,黑色图标显示但看不见。在深色模式下,浅色图标显示正常。
不久前,我尝试了一个建议,在共享应用程序中告诉它在浅色模式下使用深色模式图标。
<Shell.Resources>
<ResourceDictionary>
<Style x:Key="BaseStyle" TargetType="Element">
<Setter Property="Shell.BackgroundColor" Value="{AppThemeBinding Dark=Black, Light=#141B4D}" />
<Setter Property="Shell.ForegroundColor" Value="{AppThemeBinding Dark=White, Light=White}" />
</Style>
</ResourceDictionary>
</Shell.Resources>
但这并不起作用。因此,我真的需要一些帮助来解决这个问题。如果这不是处理这个问题的正确方式,欢迎提供一个好的替代方案。
谢谢。
英文:
How do I display the dark mode icon while in Light mode on an iOS device? I have been searching this issue for months now and every post seems to come to dead end or the solutions just don't work. Using Xamarin 17.3 & VS 2022 and and developing an app for both Android & iOS. We have the Shell's background color (<Setter Property="Shell.BackgroundColor" Value="141B4D") which is a dark blue. The default, black icons (battery, time & etc.) don't show well with this background (its a company color and can't change it.) Android seems to handle this on its own and I didn't have to make any changes & the light icons show on the dark background in both Light & Dark modes. But on iOS in light mode the black icons display but cannot be seen. In dark mode the light icons show just fine.
Awhile back I tried a suggestion to to tell it, in the shared app, to use the dark mode icons in light mode.
<Shell.Resources>
<ResourceDictionary>
<Style x:Key="BaseStyle" TargetType="Element">
<Setter Property="Shell.BackgroundColor" Value="{AppThemeBinding Dark=Black, Light=#141B4D}" />
<Setter Property="Shell.ForegroundColor" Value="{AppThemeBinding Dark=White, Light=White}" />
But this doesn't work. So I really need some help in solving this. And if this is not the proper way to handle this a good alternative is welcomed.
Thanks
答案1
得分: 0
根据您的代码,似乎您只希望状态栏中的文本或图标为白色,如果我理解正确的话。要实现这个简单的方式是在AppDelegate中添加以下代码:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
...
UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent;
return base.FinishedLaunching(app, options);
}
此外,您还需要在info.plist文件中添加以下键:
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
注意:在属性列表编辑器中,它会显示View controller-based status bar appearance。
然后,在深蓝色背景下,您也可以看到白色的图标。以下图片是在浅色模式下的效果。
希望对您有所帮助。
英文:
Based on your code, seems that you just want the text or icon in statusbar to be white if i understand correctly. So a simple way to achieve is to add the following code in AppDelegate:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
...
UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent;
return base.FinishedLaunching(app, options);
}
Also, you have to add one key in info.plist
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Note: in Property List Editor, it will show View controller-based status bar appearance
Then in dark blue background, you can also see white icon. The following picture is in light mode.
Hope it works for you.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论