Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        void Initialize(Context context, IAttributeSet attrs)
        {
            srcFirst            = this.Drawable;
            backgroundTintFirst = this.BackgroundTintList;

            if (attrs == null)
            {
                return;
            }
            var array = context.ObtainStyledAttributes(attrs, Resource.Styleable.SwitchableFab);

            srcSecond = DrawableCompat.Wrap(array.GetDrawable(Resource.Styleable.SwitchableFab_srcSecond));
            DrawableCompat.SetTint(srcSecond, Android.Graphics.Color.White.ToArgb());
            backgroundTintSecond = array.GetColorStateList(Resource.Styleable.SwitchableFab_backgroundTintSecond);
            array.Recycle();
        }
Ejemplo n.º 3
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());
                    }
                }
            }
        }