前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >win10 uwp 标题栏 扩展标题栏修改颜色透明标题栏 系统状态栏

win10 uwp 标题栏 扩展标题栏修改颜色透明标题栏 系统状态栏

作者头像
林德熙
发布2018-09-18 17:10:55
2.3K0
发布2018-09-18 17:10:55
举报

我们应用最上方的是标题栏,对于手机,最上方是状态栏。 我们可以自定义标题栏,和不显示标题栏。

下面的代码写在 OnLaunched 函数

写的位置是最前。

扩展标题栏

参见:http://dailydotnettips.com/2015/10/20/how-to-place-custom-xaml-content-in-the-windows-universal-apps-title-bar/

修改颜色

通过下面的方法可以修改颜色

 Windows.UI.Core.SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = Windows.UI.Core.AppViewBackButtonVisibility.Visible;
            ApplicationView.GetForCurrentView().TitleBar.ButtonBackgroundColor = Color.FromArgb(0xFF, 140, 206, 205);
            ApplicationView.GetForCurrentView().TitleBar.ButtonForegroundColor = Color.FromArgb(0xFF, 250, 250, 250);
            ApplicationView.GetForCurrentView().TitleBar.InactiveForegroundColor = Color.FromArgb(0xFF, 250, 250, 250);

除了上面的颜色,还有其他的一些颜色可以修改。建议是把颜色写在 xaml 然后后台去拿。

请看 UWP中实现自定义标题栏

透明标题栏 系统状态栏

手机是系统状态栏,如果不设置,会是白条,看起来不好。

我们需要安装sdk才可以。

我的 SDK 是14393,在他之前的使用也一样,在他之后的,如果以后改了,我也不知。

首先判断是不是手机 ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")

如果是的话我们可以设置 StatusBar ,上面的字符串最好复制我的,自己打可能打错

我们之前显示的白色,因为背景是空,加上没有前景。

我们可以设置背景的透明,如果设置了0,需要设置前景才看到标题。

             if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
            {
                var applicationView = ApplicationView.GetForCurrentView();
                applicationView.SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);
                var statusbar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
                statusbar.BackgroundColor = Colors.Beige;
                statusbar.BackgroundOpacity = 0.2;
                statusbar.ForegroundColor=Colors.Black;
                
            }  

其中 SetDesiredBoundsMode 是设置内容是不是可以占有标题栏

statusbar.BackgroundColor 如果设置透明为0,那么可能看不到系统显示的日期等,我们需要设置前景色。

我们还可以在上面显示Text,设置statusbar.ProgressIndicator.Text然后显示,使用函数ShowAsync

statusbar.ProgressIndicator.Text = "test statusbar";  
statusbar.ProgressIndicator.ShowAsync();

最后一个显示 Text 可以看微信,他是把消息放在标题栏。

参见:http://uwpbox.com/status-bar-at-the-top-of-the-uwp-statusbar.html

参见:http://www.cnblogs.com/tcjiaan/p/4783049.html


本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 扩展标题栏
  • 修改颜色
  • 透明标题栏 系统状态栏
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档