public override void OnViewAdded(Android.Views.View child) { base.OnViewAdded(child); if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar)) { _toolbar = (Android.Support.V7.Widget.Toolbar)child; MyNavigationPageRenderer myNavigationPageRenderer = (MyNavigationPageRenderer)Element; GradientDrawable gradientDrawable = new GradientDrawable( GradientDrawable.Orientation.LeftRight, new int[] { myNavigationPageRenderer.StartColor.ToAndroid(), myNavigationPageRenderer.EndColor.ToAndroid() }); _toolbar.SetBackgroundDrawable(gradientDrawable); _toolbar.Elevation = 0; } }
void UpdateToolbarBackground(Android.Support.V7.Widget.Toolbar toolbar, Page lastPage, Activity activity, Android.Graphics.Drawables.Drawable defaultBackground) { if (string.IsNullOrEmpty(CustomNavigationPage.GetBarBackground(lastPage)) && CustomNavigationPage.GetGradientColors(lastPage) == null) { toolbar.SetBackground(defaultBackground); } else { if (!string.IsNullOrEmpty(CustomNavigationPage.GetBarBackground(lastPage))) { toolbar.SetBackgroundResource(this.Context.Resources.GetIdentifier(CustomNavigationPage.GetBarBackground(lastPage), "drawable", Android.App.Application.Context.PackageName)); } if (CustomNavigationPage.GetGradientColors(lastPage) != null) { var colors = CustomNavigationPage.GetGradientColors(lastPage); var direction = GradientDrawable.Orientation.TopBottom; switch (CustomNavigationPage.GetGradientDirection(lastPage)) { case CustomNavigationPage.GradientDirection.BottomToTop: direction = GradientDrawable.Orientation.BottomTop; break; case CustomNavigationPage.GradientDirection.RightToLeft: direction = GradientDrawable.Orientation.RightLeft; break; case CustomNavigationPage.GradientDirection.LeftToRight: direction = GradientDrawable.Orientation.LeftRight; break; } GradientDrawable gradient = new GradientDrawable(direction, new int[] { colors.Item1.ToAndroid().ToArgb(), colors.Item2.ToAndroid().ToArgb() }); gradient.SetCornerRadius(0f); if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.JellyBean) { toolbar.SetBackground(gradient); } else { toolbar.SetBackgroundDrawable(gradient); } } } toolbar.Background.SetAlpha((int)(CustomNavigationPage.GetBarBackgroundOpacity(lastPage) * 255)); }