private void SetGradientBackground(Android.Support.V7.Widget.Toolbar toolbar)
        {
            Tuple <Color, Color> colors = new Tuple <Color, Color>(StartColor, EndColor);
            var direction             = GradientDrawable.Orientation.LeftRight;
            GradientDrawable gradient = new GradientDrawable(direction, new int[] { colors.Item1.ToAndroid().ToArgb(), colors.Item2.ToAndroid().ToArgb() });

            gradient.SetCornerRadius(0f);
            toolbar.SetBackground(gradient);
        }
Exemplo n.º 2
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);
                    toolbar.SetBackground(gradient);
                }
            }
            toolbar.Background.SetAlpha((int)(CustomNavigationPage.GetBarBackgroundOpacity(lastPage) * 255));
        }