【发布时间】:2018-11-27 23:43:00
【问题描述】:
在 MainActivity OnCreate 中,我使用以下方法设置了 StatusBar 的颜色:
Window.SetStatusBarColor(Resources.GetColor(Resource.Color.colorPrimary));
对于具体的页面,我需要设置StatusBar颜色透明。
可以在 Android 自定义呈现的类中做到这一点吗?
编辑: 我在自定义 ANDorid 上的 OnLayout 方法
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
CustomNavigation.IgnoreLayoutChange = true;
base.OnLayout(changed, l, t, r, b);
CustomNavigation.IgnoreLayoutChange = false;
int containerHeight = b - t;
PageController.ContainerArea = new Rectangle(0, 0, Context.FromPixels(r - l), Context.FromPixels(containerHeight));
if (Element?.Navigation?.NavigationStack.Count == 1)
{
CustomNavigation.BarBackgroundColor = Color.Transparent;
//HERE I NEED TO HAVE STATUS AR TRANSPARENT
}
if (Element?.Navigation?.NavigationStack.Count > 1)
{
PageController.ContainerArea = new Rectangle(0, 60, Context.FromPixels(r - l), Context.FromPixels(containerHeight));
CustomNavigation.BarBackgroundColor = Color.FromHex("#006CA6");
}
for (var i = 0; i < ChildCount; i++)
{
AView child = GetChildAt(i);
if (child is Android.Support.V7.Widget.Toolbar)
{
continue;
}
child.Layout(0, 0, r, b);
}
}
【问题讨论】:
-
我已经在你之前的问题的回答中评论过,这不起作用。
-
是的,但现在我问的是状态栏
-
哦,对不起!最好说最顶部的状态栏或最底部的状态栏,因为这几件事很令人困惑。
-
你想要这个用于 Xamarin Android 原生还是 Xamarin Forms?
-
我有一个适用于 Android 的自定义 PageRenderer。但是,如果您有 xamarin forms 解决方案,我敢打赌我可以使用它。
标签: xamarin statusbar custom-renderer