【发布时间】:2016-10-25 21:54:47
【问题描述】:
我搜索但找不到是否可以从我的可移植代码中更改每个平台的状态栏颜色? (对于Android, iOS & WinPhone 8.1)
public App()
{
// Change the StatusBar color
MainPage = new MainPageUser();
}
【问题讨论】:
-
您必须为此使用特定于平台的代码。 See 我最近写的关于如何在 WP8.1 上更改颜色的答案。
-
Android:
Window.SetStatusBarColor(Android.Graphics.Color.ParseColor("#FFFFFF")); //or any other hex value在 MainActivity。在 iOS 上,状态栏颜色取决于导航栏的颜色,因此MainPage = new NavigationPage(new MyPage()) { BarBackgroundColor = Color.FromHex("000000"), BarTextColor = Color.White };将在导航栏中创建一个黑色导航栏和带有白色文本的状态栏。要更改状态栏中的文本颜色,您必须在 info.plist 中设置<key>UIStatusBarStyle</key> <string>UIStatusBarStyleBlackTranslucent</string> -
UIStatusBarStyleBlackTranslucent表示白色文本 -
var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();其中StatusBar-Class 具有BackgroundColor、BackgroundOpacity、ForegroundColor属性 -
statusBar.BackgroundOpacity = 1;很重要,否则它将不起作用