Esempio n. 1
0
        public static AColorFilter?GetColorFilter(this ADrawable drawable)
        {
            if (drawable == null)
            {
                return(null);
            }

            return(ADrawableCompat.GetColorFilter(drawable));
        }
Esempio n. 2
0
        public static void SetColorFilter(this ADrawable drawable, AColorFilter colorFilter)
        {
            if (drawable == null)
            {
                return;
            }

            if (colorFilter == null)
            {
                ADrawableCompat.ClearColorFilter(drawable);
            }

            drawable.SetColorFilter(colorFilter);
        }
Esempio n. 3
0
        void SetIconColorFilter(TabLayout.Tab tab, bool selected)
        {
            var icon = tab.Icon;

            if (icon == null)
            {
                return;
            }

            var colors = GetItemIconTintColorState();

            if (colors == null)
            {
                ADrawableCompat.SetTintList(icon, null);
            }
            else
            {
                int[] _stateSet = null;

                if (selected)
                {
                    _stateSet = GetSelectedStateSet();
                }
                else
                {
                    _stateSet = GetEmptyStateSet();
                }

                if (colors.GetColorForState(_stateSet, _defaultAndroidColor) == _defaultARGBColor)
                {
                    ADrawableCompat.SetTintList(icon, null);
                }
                else
                {
                    var wrappedIcon = ADrawableCompat.Wrap(icon);
                    if (wrappedIcon != icon)
                    {
                        icon = wrappedIcon;
                        tab.SetIcon(wrappedIcon);
                    }

                    icon.Mutate();
                    icon.SetState(_stateSet);
                    ADrawableCompat.SetTintList(icon, colors);
                }
            }
            icon.InvalidateSelf();
        }
Esempio n. 4
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());
                    }
                }
            }
        }