Ejemplo n.º 1
0
        void UpdateBarBackgroundColor()
        {
            if (IsDisposed)
            {
                return;
            }

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

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

                if (Forms.IsLollipopOrNewer)
                {
                    if (tintColor.IsDefault)
                    {
                        _tabLayout.BackgroundTintMode = null;
                    }
                    else
                    {
                        _tabLayout.BackgroundTintMode = PorterDuff.Mode.Src;
                        _tabLayout.BackgroundTintList = ColorStateList.ValueOf(tintColor.ToAndroid());
                    }
                }
                else
                {
                    if (tintColor.IsDefault && _backgroundDrawable != null)
                    {
                        _tabLayout.SetBackground(_backgroundDrawable);
                    }
                    else if (!tintColor.IsDefault)
                    {
                        // if you don't create a new drawable then SetBackgroundColor
                        // just sets the color on the background drawable that's saved
                        // it doesn't create a new one
                        if (_backgroundDrawable == null && _tabLayout.Background != null)
                        {
                            _backgroundDrawable        = _tabLayout.Background;
                            _wrappedBackgroundDrawable = ADrawableCompat.Wrap(_tabLayout.Background).Mutate();
                        }

                        if (_wrappedBackgroundDrawable != null)
                        {
                            _tabLayout.Background = _wrappedBackgroundDrawable;
                        }

                        _tabLayout.SetBackgroundColor(tintColor.ToAndroid());
                    }
                }
            }
        }