Windows 10 个移动应用中带有黑色字体的黑色状态栏
Black StatusBar with black font in Windows 10 mobile app
我在移动设备上有一个 Windows 10 UWP 应用 运行ning。当我 运行 模拟器中的应用程序时,一切正常。当我在设备 (Lumia 550) 上 运行 时,状态栏为黑色,字体为黑色,状态指示器不可见。
这是某种错误吗?
我知道我可以强制 StatusBar 具有白色背景和黑色,但应用程序的要求是坚持主题(深色主题中的黑色 StatusBar,浅色主题中的白色)。
如果我创建一个新的空 Windows 10 应用程序并在设备上 运行 它,问题是一样的,它不是特定于我的应用程序。
编辑
这是一个更合适的答案:
在 Windows 10 Mobile 中,状态栏从最顶层页面继承其背景颜色。前景色继承自RequestedTheme
.
这意味着,如果您将页面的背景颜色设置为黑色,并将 RequestedTheme
设置为 Light
(这会产生白色前景色),则文本将是黑色的。
原版post
你读过这个吗?:https://stenobot.wordpress.com/2015/07/08/uwp-app-development-styling-the-mobile-status-bar/
可能对你有帮助。
我对此有点挣扎。
奇怪的是,当我启动我的应用程序时,主题 (Application.RequestedTheme
) 是 always Light,忽略 phone 上的设置。即使我尝试在构造函数中将它设置为 Dark,它也会立即恢复为 Light。这可以解释黑色前景色。
我也遇到过模拟器和设备不一致的问题。为了解决这个问题,我(按照其他答案中的建议)设置 页面 (不是根网格)的背景颜色:
<Page
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
... >
</Page>
有了这个,状态栏至少看起来是可读的。
只需在App.xaml
中添加RequestedTheme="Dark"
在您的参考管理器中添加 Windows UWP 的移动扩展
然后在 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;
}
}
如果您的 Light 主题项目在黑色背景上使用黑色字体,只需将此行添加到 App.xaml.cs
中的 OnLaunched
方法中:
rootFrame.Background = new SolidColorBrush(Colors.White);
我在移动设备上有一个 Windows 10 UWP 应用 运行ning。当我 运行 模拟器中的应用程序时,一切正常。当我在设备 (Lumia 550) 上 运行 时,状态栏为黑色,字体为黑色,状态指示器不可见。
这是某种错误吗?
我知道我可以强制 StatusBar 具有白色背景和黑色,但应用程序的要求是坚持主题(深色主题中的黑色 StatusBar,浅色主题中的白色)。
如果我创建一个新的空 Windows 10 应用程序并在设备上 运行 它,问题是一样的,它不是特定于我的应用程序。
编辑
这是一个更合适的答案:
在 Windows 10 Mobile 中,状态栏从最顶层页面继承其背景颜色。前景色继承自RequestedTheme
.
这意味着,如果您将页面的背景颜色设置为黑色,并将 RequestedTheme
设置为 Light
(这会产生白色前景色),则文本将是黑色的。
原版post
你读过这个吗?:https://stenobot.wordpress.com/2015/07/08/uwp-app-development-styling-the-mobile-status-bar/
可能对你有帮助。
我对此有点挣扎。
奇怪的是,当我启动我的应用程序时,主题 (Application.RequestedTheme
) 是 always Light,忽略 phone 上的设置。即使我尝试在构造函数中将它设置为 Dark,它也会立即恢复为 Light。这可以解释黑色前景色。
我也遇到过模拟器和设备不一致的问题。为了解决这个问题,我(按照其他答案中的建议)设置 页面 (不是根网格)的背景颜色:
<Page
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
... >
</Page>
有了这个,状态栏至少看起来是可读的。
只需在App.xaml
中添加RequestedTheme="Dark"
在您的参考管理器中添加 Windows UWP 的移动扩展
然后在 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;
}
}
如果您的 Light 主题项目在黑色背景上使用黑色字体,只需将此行添加到 App.xaml.cs
中的 OnLaunched
方法中:
rootFrame.Background = new SolidColorBrush(Colors.White);