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)); }
void SetupBackground() { if (string.IsNullOrEmpty(CustomNavigationPage.GetBarBackground(Element)) && CustomNavigationPage.GetGradientColors(Element) == null) { SetupBackground(null, CustomNavigationPage.GetBarBackgroundOpacity(Element)); } else { if (!string.IsNullOrEmpty(CustomNavigationPage.GetBarBackground(Element))) { SetupBackground(UIImage.FromBundle(CustomNavigationPage.GetBarBackground(Element)), CustomNavigationPage.GetBarBackgroundOpacity(Element)); } else if (CustomNavigationPage.GetGradientColors(Element) != null) { SetupBackground(CreateGradientBackground(CustomNavigationPage.GetGradientColors(Element).Item1, CustomNavigationPage.GetGradientColors(Element).Item2, CustomNavigationPage.GetGradientDirection(Element)), CustomNavigationPage.GetBarBackgroundOpacity(Element)); } } }