【问题标题】:How do you change the title bar color in a Windows Universal app?如何更改 Windows 通用应用程序中的标题栏颜色?
【发布时间】:2015-10-28 19:10:24
【问题描述】:

我希望更改标题栏的颜色以更好地适应我的应用程序,类似于在邮件应用程序中所做的。我该怎么做呢?

【问题讨论】:

    标签: windows-runtime windows-10 win-universal-app uwp


    【解决方案1】:

    您可以通过在标题栏中添加扩展视图来自定义按钮和标题文本。请为此查找代码 sn-p。

    private void ExtendViewOftitleBar()
    {
            CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
            ApplicationView view = ApplicationView.GetForCurrentView();
            ApplicationViewTitleBar titleBar = view.TitleBar;
            view.SuppressSystemOverlays = true;
            titleBar.BackgroundColor = Windows.UI.Color.FromArgb(0, 0, 0, 0);
            titleBar.ForegroundColor = Windows.UI.Color.FromArgb(0, 0, 0, 0);
            titleBar.InactiveBackgroundColor = Windows.UI.Color.FromArgb(0, 0, 0, 0);
            titleBar.InactiveForegroundColor = Windows.UI.Color.FromArgb(0, 0, 0, 0);
            titleBar.ButtonBackgroundColor = Windows.UI.Color.FromArgb(0, 0, 0, 0);
            titleBar.ButtonHoverBackgroundColor = Windows.UI.Color.FromArgb(0, 0, 0, 0);
            titleBar.ButtonPressedBackgroundColor = Windows.UI.Color.FromArgb(0, 0, 0, 0);
            titleBar.ButtonInactiveBackgroundColor = Windows.UI.Color.FromArgb(0, 0, 0, 0);
    

    }

    【讨论】:

      【解决方案2】:

      TitleBar 各部分的背景色和前景色可以改变如下。

      ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar;
      titleBar.BackgroundColor = Colors.Black;
      titleBar.ForegroundColor = Colors.White;
      titleBar.ButtonBackgroundColor = Colors.Black;
      titleBar.ButtonForegroundColor = Colors.White;
      

      请注意,这些更改是在应用显示后发生的,因此用户会看到颜色发生了变化。

      【讨论】:

      • 它似乎没有改变 Windows 10 移动版状态栏的颜色。我必须为此做些不同的事情吗?
      • 不确定是否还需要,但是当您想要更改状态栏的颜色时,您需要添加额外的代码。先看看你是不是移动家庭:if(Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Mobile") 之后,抓住状态栏,设置ForegroundColor和BackgroundColo
      • @Depechie 不要检查 DeviceFamily;那是分析信息,而不是用于程序决策。要查看状态栏 API 是否可用(注意:状态栏可能出现在移动设备以外的设备上),请使用 Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")
      • @RaymondChen true... 直到最近才知道该 API 信息密钥 :)
      【解决方案3】:

      您可以通过执行以下操作自定义标题栏的背景:

      var appView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView();
      var titleBar = appView.TitleBar;
      titleBar.BackgroundColor = Colors.Black;
      

      您可以通过更改其他属性中的颜色来更改标题栏的其他颜色,例如前景色或按钮颜色。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-02-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-13
        相关资源
        最近更新 更多