更改 Xamarin.Forms 应用中顶部和底部栏(ControlsBar、StatusBar)的颜色 [英] Change the color of the top and bottom bar (ControlsBar, StatusBar) in a Xamarin.Forms app
问题描述
无论如何,即使需要平台特定的代码,也可以更改顶部栏(蓝色)和底部栏(黑色)的颜色?
Is there anyway, even if requires platform specific code behind, to change the color of both the top bar (the one in blue) and the bottom bar (the one in black)?
我希望添加对明暗模式的支持,因此我希望能够在运行时进行更改.
I wish to add support for light and dark modes, so I would like to be able to change that during runtime.
推荐答案
有可能 .
安卓:
使用 Window.SetStatusBarColor
和 Window.SetNavigationBarColor
可以在 Android API 21 以上轻松做到这一点.
Using Window.SetStatusBarColor
and Window.SetNavigationBarColor
can do that easily above Android API 21.
if (Build.VERSION.SdkInt >= Build.VERSION_CODES.Lollipop)
{
Window.SetStatusBarColor(Android.Graphics.Color.Orange);
Window.SetNavigationBarColor(Android.Graphics.Color.Orange);
}
IOS:
在ios中,更改导航栏和状态栏,可以如下使用:
In ios, change navigation bar and status bar , can use as bellow:
NavigationController.NavigationBar.BarTintColor = UIColor.YouWantColor;
// Color you want, such as UIColor.Green
点击按钮后,动态变为绿色.
After click button, changed dynamically to green color.
这篇关于更改 Xamarin.Forms 应用中顶部和底部栏(ControlsBar、StatusBar)的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!