public virtual void initialise(bool setActiveColor) { iconView.Selected = false; if (isInActiveIconSet) { StateListDrawable states = new StateListDrawable(); states.AddState(new int[] { Android.Resource.Attribute.StateSelected }, mCompactIcon); states.AddState(new int[] { -Android.Resource.Attribute.StateSelected }, mCompactInActiveIcon); states.AddState(new int[] {}, mCompactInActiveIcon); iconView.SetImageDrawable(states); } else { if (setActiveColor) { DrawableCompat.SetTintList(mCompactIcon, new ColorStateList(new int[][] { new int[] { Android.Resource.Attribute.StateSelected }, new int[] { -Android.Resource.Attribute.StateSelected }, new int[] {} }, new int[] { mActiveColor, mInActiveColor, mInActiveColor })); } else { DrawableCompat.SetTintList(mCompactIcon, new ColorStateList(new int[][] { new int[] { Android.Resource.Attribute.StateSelected }, new int[] { -Android.Resource.Attribute.StateSelected }, new int[] {} }, new int[] { mBackgroundColor, mInActiveColor, mInActiveColor })); } iconView.SetImageDrawable(mCompactIcon); } }
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(); }