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 UpdateToolbar() { if (_disposed) { return; } Context context = Context; var activity = (FormsAppCompatActivity)context; AToolbar bar = _toolbar; ActionBarDrawerToggle toggle = _drawerToggle; if (bar == null) { return; } bool isNavigated = NavigationPageController.StackDepth > 1; bar.NavigationIcon = null; Page currentPage = Element.CurrentPage; if (isNavigated) { if (toggle != null) { toggle.DrawerIndicatorEnabled = false; toggle.SyncState(); } if (NavigationPage.GetHasBackButton(currentPage)) { var icon = new DrawerArrowDrawable(activity.SupportActionBar.ThemedContext); icon.Progress = 1; bar.NavigationIcon = icon; var prevPage = Element.Peek(1); _defaultNavigationContentDescription = bar.SetNavigationContentDescription(prevPage, _defaultNavigationContentDescription); } } else { if (toggle != null && _masterDetailPage != null) { toggle.DrawerIndicatorEnabled = _masterDetailPage.ShouldShowToolbarButton(); toggle.SyncState(); } } Color tintColor = Element.BarBackgroundColor; if (Forms.IsLollipopOrNewer) { if (tintColor.IsDefault) { bar.BackgroundTintMode = null; } else { bar.BackgroundTintMode = PorterDuff.Mode.Src; bar.BackgroundTintList = ColorStateList.ValueOf(tintColor.ToAndroid()); } } else { if (tintColor.IsDefault && _backgroundDrawable != null) { bar.SetBackground(_backgroundDrawable); } else if (!tintColor.IsDefault) { if (_backgroundDrawable == null) { _backgroundDrawable = bar.Background; } bar.SetBackgroundColor(tintColor.ToAndroid()); } } Color textColor = Element.BarTextColor; if (!textColor.IsDefault) { bar.SetTitleTextColor(textColor.ToAndroid().ToArgb()); } bar.Title = currentPage.Title ?? ""; UpdateTitleIcon(); UpdateTitleView(); }