修改显示xamarin开发的App的手机顶部状态栏,
步骤一:在项目UWP上的“引用”里右键“添加引用”,选择->Universal Windows->Windows Mobile Extensions for the UWP 选项,添加引用,
步骤二:在App.xaml.cs 类OnLaunchedl里添加如下代码:
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) {//判断是否有状态栏,PC无状态栏会出错 StatusBar bar = StatusBar.GetForCurrentView(); bar.ForegroundColor = Colors.White; Color bgColor = Color.FromArgb(255, 54, 188, 99); bar.BackgroundColor = bgColor; bar.BackgroundOpacity = 1d;//1表示不透明 d:double }
步骤三: 在App.xaml.cs 类OnSuspending里添加:
//全屏设置
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
总结:其中的bar.BackgroundColor可以设置为自己想要的颜色,也可注释掉,不设置颜色,不设置颜色是背景色为明暗两种主题的颜色,即黑底白字或者白底黑字两种。即使设置为各种颜色主题,但是顶部状态栏只有这两种。