Beispiel #1
0
        internal void UpdateBarBackgroundColor()
        {
            if (Element.BarBackground != null)
            {
                return;
            }

            if (IsBottomTabPlacement)
            {
                Color tintColor = Element.BarBackgroundColor;

                if (tintColor == null)
                {
                    _bottomNavigationView.SetBackground(null);
                }
                else if (tintColor != null)
                {
                    _bottomNavigationView.SetBackgroundColor(tintColor.ToPlatform());
                }
            }
            else
            {
                Color tintColor = Element.BarBackgroundColor;

                if (tintColor == null)
                {
                    _tabLayout.BackgroundTintMode = null;
                }
                else
                {
                    _tabLayout.BackgroundTintMode = PorterDuff.Mode.Src;
                    _tabLayout.BackgroundTintList = ColorStateList.ValueOf(tintColor.ToPlatform());
                }
            }
        }
Beispiel #2
0
        protected virtual ColorStateList GetItemTextColorStates()
        {
            if (_originalTabTextColors == null)
            {
                _originalTabTextColors = (IsBottomTabPlacement) ? _bottomNavigationView.ItemTextColor : _tabLayout.TabTextColors;
            }

            Color barItemColor         = BarItemColor;
            Color barTextColor         = Element.BarTextColor;
            Color barSelectedItemColor = BarSelectedItemColor;

            if (barItemColor == null && barTextColor == null && barSelectedItemColor == null)
            {
                return(_originalTabTextColors);
            }

            if (_newTabTextColors != null)
            {
                return(_newTabTextColors);
            }

            int checkedColor;
            int defaultColor;

            if (barTextColor != null)
            {
                checkedColor = barTextColor.ToPlatform().ToArgb();
                defaultColor = checkedColor;
            }
            else
            {
                defaultColor = barItemColor.ToPlatform().ToArgb();

                if (barItemColor == null && _originalTabTextColors != null)
                {
                    defaultColor = _originalTabTextColors.DefaultColor;
                }

                checkedColor = defaultColor;

                if (barSelectedItemColor != null)
                {
                    checkedColor = barSelectedItemColor.ToPlatform().ToArgb();
                }
            }

            _newTabTextColors = GetColorStateList(defaultColor, checkedColor);
            return(_newTabTextColors);
        }
Beispiel #3
0
        protected virtual ColorStateList GetItemIconTintColorState()
        {
            if (IsBottomTabPlacement)
            {
                if (_orignalTabIconColors == null)
                {
                    _orignalTabIconColors = _bottomNavigationView.ItemIconTintList;
                }
            }
            // this ensures that existing behavior doesn't change
            else if (!IsBottomTabPlacement && BarSelectedItemColor != null && BarItemColor == null)
            {
                return(null);
            }

            Color barItemColor         = BarItemColor;
            Color barSelectedItemColor = BarSelectedItemColor;

            if (barItemColor == null && barSelectedItemColor == null)
            {
                return(_orignalTabIconColors);
            }

            if (_newTabIconColors != null)
            {
                return(_newTabIconColors);
            }

            int defaultColor = barItemColor.ToPlatform().ToArgb();

            if (barItemColor == null && _orignalTabIconColors != null)
            {
                defaultColor = _orignalTabIconColors.DefaultColor;
            }

            int checkedColor = defaultColor;

            if (barSelectedItemColor != null)
            {
                checkedColor = barSelectedItemColor.ToPlatform().ToArgb();
            }

            _newTabIconColors = GetColorStateList(defaultColor, checkedColor);
            return(_newTabIconColors);
        }
Beispiel #4
0
        public static void UpdateBackground(this GradientDrawable gradientDrawable, Brush brush, int height, int width)
        {
            if (gradientDrawable == null || brush == null || brush.IsEmpty)
            {
                return;
            }

            if (brush is SolidColorBrush solidColorBrush)
            {
                Color bgColor = solidColorBrush.Color;
                gradientDrawable.SetColor(bgColor?.ToPlatform() ?? Colors.Transparent.ToPlatform());
            }

            if (brush is LinearGradientBrush linearGradientBrush)
            {
                var p1 = linearGradientBrush.StartPoint;
                var x1 = (float)p1.X;
                var y1 = (float)p1.Y;

                var p2 = linearGradientBrush.EndPoint;
                var x2 = (float)p2.X;
                var y2 = (float)p2.Y;

                const double Rad2Deg = 180.0 / Math.PI;

                float xDiff = x2 - x1;
                float yDiff = y2 - y1;

                double angle = Math.Atan2(yDiff, xDiff) * Rad2Deg;

                if (angle < 0)
                {
                    angle += 360;
                }

                var gradientBrushData = linearGradientBrush.GetGradientBrushData();
                var colors            = gradientBrushData.Item1;

                if (colors.Length < 2)
                {
                    return;
                }

                gradientDrawable.SetGradientType(GradientType.LinearGradient);
                gradientDrawable.SetColors(colors);
                SetGradientOrientation(gradientDrawable, angle);
            }

            if (brush is RadialGradientBrush radialGradientBrush)
            {
                var   center  = radialGradientBrush.Center;
                float centerX = (float)center.X;
                float centerY = (float)center.Y;
                float radius  = (float)radialGradientBrush.Radius;

                var gradientBrushData = radialGradientBrush.GetGradientBrushData();
                var colors            = gradientBrushData.Item1;

                if (colors.Length < 2)
                {
                    return;
                }

                gradientDrawable.SetGradientType(GradientType.RadialGradient);
                gradientDrawable.SetGradientCenter(centerX, centerY);
                gradientDrawable.SetGradientRadius(Math.Max(height, width) * radius);
                gradientDrawable.SetColors(colors);
            }
        }