【问题标题】:Black StatusBar with black font in Windows 10 mobile appWindows 10 移动应用程序中带有黑色字体的黑色状态栏
【发布时间】:2015-12-15 08:53:23
【问题描述】:

我有一个在移动设备上运行的 Windows 10 UWP 应用。当我在模拟器中运行应用程序时,一切正常。当我在设备 (Lumia 550) 上运行它时,StatusBar 是黑色的,带有黑色字体,并且状态指示器不可见。

这是某种错误吗?

我知道我可以强制 StatusBar 具有白色背景和黑色,但应用程序的要求是坚持主题(深色主题中的黑色 StatusBar,浅色主题中的白色)。

如果我创建一个新的空 Windows 10 应用并在设备上运行它,问题是一样的,它不是我的应用所特有的。

【问题讨论】:

  • 对我来说似乎是一个错误,如果它也发生在一个空项目中...您正在运行 build 10586.29 吗?
  • 是的,L550 上的 10.0.10586.29。
  • 请问如果您将主题更改为浅色项目,空项目会是什么样子?那是白底白字吗?
  • 默认灯光主题

标签: c# xaml win-universal-app uwp


【解决方案1】:

编辑
这是一个更正确的答案:

在 Windows 10 移动版中,状态栏从最顶部的页面继承其背景颜色。前景色继承自RequestedTheme

这意味着,如果您将页面的背景颜色设置为黑色,并将您的 RequestedTheme 设置为 Light(提供白色前景色),则文本将为黑底黑字。

原帖
你读过这个吗?:https://stenobot.wordpress.com/2015/07/08/uwp-app-development-styling-the-mobile-status-bar/

也许对你有帮助。

【讨论】:

    【解决方案2】:

    我在这方面有点挣扎。

    奇怪的是,当我启动我的应用程序时,主题 (Application.RequestedTheme) 是 always Light,忽略了手机上的设置。即使我尝试在构造函数中将其设置为 Dark,它也会立即恢复为 Light。这可以解释黑色的前景色。

    我也遇到了模拟器和设备之间的不一致。为了解决这个问题,我(如其他答案中所建议)设置了 page (不是根网格)的背景颜色:

    <Page
        Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
        ... >
    
    </Page>
    

    这样,状态栏至少看起来可读。

    【讨论】:

    • 对我来说 Background="{ThemeResource ApplicationHeaderForegroundThemeBrush}" 有效
    【解决方案3】:

    如果您的 Light 主题项目在黑色背景上有黑色字体,只需将此行添加到 App.xaml.cs 中的 OnLaunched 方法中:

    rootFrame.Background = new SolidColorBrush(Colors.White);
    

    【讨论】:

      【解决方案4】:

      只需在 App.xaml 中添加 RequestedTheme="Dark"

      【讨论】:

        【解决方案5】:

        在参考管理器中为 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;
            }
         }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-04-11
          • 1970-01-01
          • 2017-11-28
          • 1970-01-01
          • 2011-10-11
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多