在Windows 10移动应用程序中使用黑色字体的黑色StatusBar
我有一个在移动设备上运行的Windows 10 UWP应用程序。 当我在模拟器中运行应用程序时,一切正常。 当我在设备(Lumia 550)上运行它时,StatusBar是黑色的,带有黑色字体,状态指示器不可见。
这是某种错误吗?
我知道我可以强制StatusBar有白色背景和黑色,但应用程序的要求是坚持主题(黑色主题中的黑色StatusBar,Light主题中的白色)。
如果我创建一个新的空Windows 10应用程序并在设备上运行它,问题是相同的,它不是我的应用程序特定的。
编辑
这是一个更恰当的答案:
在Windows 10 Mobile中,状态栏从最顶层的页面inheritance它的背景颜色。 前景色inheritance自RequestedTheme
。
这意味着如果您将页面的背景颜色设置为黑色并将RequestedTheme
为Light
(这将提供白色前景色),则文本将为黑色黑色。
原帖
你读过这个吗?: https : //stenobot.wordpress.com/2015/07/08/uwp-app-development-styling-the-mobile-status-bar/
它可能对你有所帮助。
我有点挣扎。
奇怪的是,当我启动我的应用程序时,主题( Application.RequestedTheme
) 总是 Light,忽略手机上的设置。 即使我在构造函数中尝试将其设置为Dark,它也会立即恢复为Light。 这可以解释黑色前景色。
我也遇到了模拟器和设备之间的不一致。 为了解决这个问题,我(在其他答案中建议)设置页面的背景颜色(不是根网格):
有了这个,状态栏至少看起来是可读的。
如果您使用Light主题项目在黑色背景上获得黑色字体,只需将此行添加到App.xaml.cs
OnLaunched
方法中:
rootFrame.Background = new SolidColorBrush(Colors.White);
只需在App.xaml中添加RequestedTheme="Dark"
在您的参考管理器中,为UWP添加Windows Mobile扩展
然后在App.XAML.cs
上
protected override void OnLaunched(LaunchActivatedEventArgs e)
加
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")) { var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView(); statusBar.BackgroundColor = Windows.UI.Colors.Green; statusBar.BackgroundOpacity = 1; statusBar.ForegroundColor = Colors.White; }
如果你想在PC版UWP应用程序上更改标题栏,那么你可以使用它
if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.ApplicationView")) { var titleBar = ApplicationView.GetForCurrentView().TitleBar; if (titleBar != null) { titleBar.ButtonBackgroundColor = Colors.DarkBlue; titleBar.ButtonForegroundColor = Colors.White; titleBar.BackgroundColor = Colors.Blue; titleBar.ForegroundColor = Colors.White; } }