Exemplo n.º 1
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (setup)
            {
                return;
            }

            if (e.PropertyName == "Renderer")
            {
                var layout = (TabLayout)ViewGroup.GetChildAt(1);
                setup = true;
                var            iconTab = Resource.Drawable.icon_tab;
                ColorStateList colors  = Build.VERSION.SdkInt >= BuildVersionCodes.M ?
                                         Resources.GetColorStateList(iconTab, MainApplication.CurrentContext.Theme) :
                                         Resources.GetColorStateList(Resource.Drawable.icon_tab);
                layout.SetBackgroundColor(Color.White.ToAndroid());
                for (int i = 0; i < layout.TabCount; i++)
                {
                    var tab  = layout.GetTabAt(i);
                    var icon = tab.Icon;
                    if (icon != null)
                    {
                        icon = DrawableCompat.Wrap(icon);
                        DrawableCompat.SetTintList(icon, colors);
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            if ((int)Build.VERSION.SdkInt >= 21)
            {
                Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
            }

            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            var fragments = new V4Fragment[]
            {
                new HomeFragment(),
                new PerformanceFragment(),
                new CollectionFragment()
            };
            var titles = (new int[] {
                Resource.String.strHome,
                Resource.String.strPerformance,
                Resource.String.strCollection
            });

            var toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.app_bar);

            SetSupportActionBar(toolbar);
            SupportActionBar.SetTitle(titles[0]);
            var tabLayout = FindViewById <TabLayout>(Resource.Id.sliding_tabsIcon);

            var viewPager = FindViewById <ViewPager>(Resource.Id.viewpagerIcon);

            viewPager.Adapter = new TabsFragmentPagerAdapter(SupportFragmentManager, fragments, titles);
            tabLayout.SetupWithViewPager(viewPager);

            var homeIcon        = VectorDrawableCompat.Create(Resources, Resource.Drawable.ic_home, Theme);
            var performanceIcon = VectorDrawableCompat.Create(Resources, Resource.Drawable.ic_barChart, Theme);
            var collectionIcon  = VectorDrawableCompat.Create(Resources, Resource.Drawable.ic_collection, Theme);

            tabLayout.GetTabAt(0).SetIcon(homeIcon);
            tabLayout.GetTabAt(1).SetIcon(performanceIcon);
            tabLayout.GetTabAt(2).SetIcon(collectionIcon);

            var tabIconColors = ContextCompat.GetColorStateList(this, Resource.Drawable.tab_colors);

            for (int i = 0; i < 3; i++)
            {
                var iconWrap = DrawableCompat.Wrap(tabLayout.GetTabAt(i).Icon);
                DrawableCompat.SetTintList(iconWrap, tabIconColors);
                tabLayout.GetTabAt(i).SetIcon(iconWrap);
            }

            tabLayout.TabSelected += (object sender, TabLayout.TabSelectedEventArgs e) =>
            {
                var tab = e.Tab;
                viewPager.SetCurrentItem(tab.Position, true);
                SupportActionBar.SetTitle(titles[tab.Position]);
            };
        }
Exemplo n.º 3
0
 /// <summary>
 /// Helper method used to assign a color state list to the specified layer if it exists.
 /// </summary>
 /// <param name="drawable">Drawable.</param>
 /// <param name="index">Index.</param>
 /// <param name="colorList">Color list.</param>
 public static void SetLayerTintList(LayerDrawable drawable, int index, ColorStateList colorList)
 {
     if (drawable?.NumberOfLayers > index)
     {
         var layer   = drawable.GetDrawable(index);
         var wrapper = DrawableCompat.Wrap(layer);
         DrawableCompat.SetTintList(wrapper, colorList);
     }
 }
Exemplo n.º 4
0
 private void CreateGuage()
 {
     RingDrawable?.SetColors(new int[] { RingColors.StartColor, RingColors.EndColor });
     DrawableCompat.SetTintList(CenterDrawable, CenterTint);
     _inactiveCircularEventGaugeDrawable = CreateGaugeDrawable();
     _circularEventGaugeDrawable         = CreateRotateDrawable(_inactiveCircularEventGaugeDrawable);
     Indicator.IndeterminateDrawable     = _circularEventGaugeDrawable;
     Background = _inactiveCircularEventGaugeDrawable;
 }
Exemplo n.º 5
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.tabs_activity);

            var toolBar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);

            SetSupportActionBar(toolBar);

            var fragments = new Fragment[]
            {
                fragment1,
                fragment2,
                fragment3,
            };

            var viewPager = FindViewById <ViewPager>(Resource.Id.viewPager);

            viewPager.Adapter = new IconTabsFragmentPagerAdapter(SupportFragmentManager, fragments);

            var tabLayout = FindViewById <TabLayout>(Resource.Id.sliding_tabs);

            tabLayout.SetupWithViewPager(viewPager);

            //tabLayout.GetTabAt(0).SetIcon(Resource.Drawable.ic_filter_1_white_24dp);
            //tabLayout.GetTabAt(1).SetIcon(Resource.Drawable.ic_filter_2_white_24dp);
            //tabLayout.GetTabAt(2).SetIcon(Resource.Drawable.ic_filter_3_white_24dp);

            var tabIconColors = Build.VERSION.SdkInt >= BuildVersionCodes.M
                        ? Resources.GetColorStateList(Resource.Drawable.tab_icon_color, Theme)
                        : Resources.GetColorStateList(Resource.Drawable.tab_icon_color);

            var icon1 = GetDrawable(Resource.Drawable.ic_filter_1_white_24dp);
            var icon2 = GetDrawable(Resource.Drawable.ic_filter_2_white_24dp);
            var icon3 = GetDrawable(Resource.Drawable.ic_filter_3_white_24dp);

            var tab1 = tabLayout.GetTabAt(0);
            var tab2 = tabLayout.GetTabAt(1);
            var tab3 = tabLayout.GetTabAt(2);

            // We wrap the icon to support API < 21
            var iconWrap = DrawableCompat.Wrap(icon1);

            DrawableCompat.SetTintList(iconWrap, tabIconColors);
            tab1.SetIcon(iconWrap);

            iconWrap = DrawableCompat.Wrap(icon2);
            DrawableCompat.SetTintList(iconWrap, tabIconColors);
            tab2.SetIcon(iconWrap);

            iconWrap = DrawableCompat.Wrap(icon3);
            DrawableCompat.SetTintList(iconWrap, tabIconColors);
            tab3.SetIcon(iconWrap);
        }
Exemplo n.º 6
0
        protected override void Render()
        {
            var native  = Native;
            var element = Element;

            // Visibility
            if (element.Visibility == Visibility.Visible)
            {
                // Icon
                var iconUri = (element.Icon as BitmapIcon)?.UriSource;

                if (iconUri != null)
                {
                    native.NavigationIcon = DrawableHelper.FromUri(iconUri);
                }

                // Foreground
                var foreground        = (element.Foreground as SolidColorBrush);
                var foregroundOpacity = foreground?.Opacity ?? 0;

                if (FeatureConfiguration.AppBarButton.EnableBitmapIconTint)
                {
                    var foregroundColor = foreground?.Color;
                    if (native.NavigationIcon != null)
                    {
                        if (foreground != null)
                        {
                            DrawableCompat.SetTint(native.NavigationIcon, (Android.Graphics.Color)foregroundColor);
                        }
                        else
                        {
                            DrawableCompat.SetTintList(native.NavigationIcon, null);
                        }
                    }
                }

                // Label
                native.NavigationContentDescription = element.Label;

                // Opacity
                var opacity      = element.Opacity;
                var finalOpacity = foregroundOpacity * opacity;
                var alpha        = (int)(finalOpacity * 255);
                native.NavigationIcon?.SetAlpha(alpha);
            }
            else
            {
                native.NavigationIcon = null;
                native.NavigationContentDescription = null;
            }
        }
Exemplo n.º 7
0
        /// <inheritdoc />
        protected override void SetTabIcon(TabLayout.Tab tab, FileImageSource icon)
        {
            var iconize = Iconize.FindIconForKey(icon.File);

            if (!(iconize is null))
            {
                var drawable = new IconDrawable(Context, icon).SizeDp(20);
                DrawableCompat.SetTintList(drawable, GetItemIconTintColorState());
                tab.SetIcon(drawable);
                return;
            }

            base.SetTabIcon(tab, icon);
        }
Exemplo n.º 8
0
        public Drawable ChangeColorTint(Drawable drawable, ColorStateList tint)
        {
            if (drawable == null || tint == null)
            {
                return(null);
            }

            var wrapped = DrawableCompat.Wrap(drawable);

            // This should avoid tinting all the arrows
            wrapped = wrapped.Mutate();
            DrawableCompat.SetTintList(wrapped, tint);
            return(wrapped);
        }
        private Drawable getSelector(int normalColor, int pressedColor,
                                     int disabledColor, int shape)
        {
            Drawable drawable = DrawableCompat.Wrap(GetVectorDrawable(shape)).Mutate();

            DrawableCompat.SetTintList(
                drawable,
                new ColorStateList(
                    new int[][] {
                new int[] { Android.Resource.Attribute.StateEnabled, -Android.Resource.Attribute.StatePressed },
                new int[] { Android.Resource.Attribute.StateEnabled, Android.Resource.Attribute.StatePressed },
                new int[] { -Android.Resource.Attribute.StateEnabled }
            },
                    new int[] { normalColor, pressedColor, disabledColor }
                    ));
            return(drawable);
        }
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (setup)
            {
                return;
            }

            if (e.PropertyName == "Renderer")
            {
                tabbedPage = (CoreTabbedPage)Element;
                if (!tabbedPage.IsToolbarBottom)
                {
                    //var groupName = ViewGroup.GetChildAt(0).GetType().Name;
                    layout = (TabLayout)ViewGroup.GetChildAt(1);
                    setup  = true;

                    ColorStateList colors = CreateColorState();

                    layout?.SetTabTextColors(tabbedPage.UnSelectedForegroundColor.ToAndroid(), tabbedPage.SelectedForegroundColor.ToAndroid());

                    if (tabbedPage.TabBackgroundColor != Color.Default)
                    {
                        layout?.SetBackgroundColor(tabbedPage.TabBackgroundColor.ToAndroid());
                    }

                    if (layout != null)
                    {
                        for (int i = 0; i < layout.TabCount; i++)
                        {
                            var tab  = layout.GetTabAt(i);
                            var icon = tab.Icon;
                            if (icon != null)
                            {
                                icon = DrawableCompat.Wrap(icon);
                                DrawableCompat.SetTintList(icon, colors);
                            }
                        }
                    }
                }
            }
        }
        public static void SetDrawableTint(this Drawable drawable, ColorStateList tint, bool correctEnabled = false)
        {
            if (tint != null)
            {
                if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                {
                    drawable.SetTintList(tint);
                }
                else
                {
                    DrawableCompat.SetTintList(drawable, tint);
                }

                // A bug means  _drawableCenter seems to only be picking up the disabled colour form the ColorStateList, so set color manually
                if (correctEnabled)
                {
                    CorrectDrawableTint(drawable, tint);
                }
            }
        }
Exemplo n.º 12
0
        public static void SetTint(RadioButton radioButton, Color color)
        {
            ColorStateList sl = new ColorStateList(new int[][] {
                new int[] { -Android.Resource.Attribute.StateChecked },
                new int[] { Android.Resource.Attribute.StateChecked }
            }
                                                   , new int[] {
                DialogUtils.ResolveColor(radioButton.Context, Resource.Attribute.colorControlNormal), color
            });

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                radioButton.ButtonTintList = sl;
            }
            else
            {
                Drawable d = ContextCompat.GetDrawable(radioButton.Context, Resource.Drawable.abc_btn_radio_material);
                DrawableCompat.SetTintList(d, sl);
                radioButton.SetButtonDrawable(d);
            }
        }
Exemplo n.º 13
0
        protected override void Render()
        {
            // Visibility
            if (Element.Visibility == Visibility.Visible)
            {
                // Icon
                var iconUri = (Element.Icon as BitmapIcon)?.UriSource;
                Native.NavigationIcon = DrawableHelper.FromUri(iconUri);

                // Foreground
                var foreground        = (Element.Foreground as SolidColorBrush);
                var foregroundColor   = foreground?.Color;
                var foregroundOpacity = foreground?.Opacity ?? 0;
                if (Native.NavigationIcon != null)
                {
                    if (foreground != null)
                    {
                        DrawableCompat.SetTint(Native.NavigationIcon, (Android.Graphics.Color)foregroundColor);
                    }
                    else
                    {
                        DrawableCompat.SetTintList(Native.NavigationIcon, null);
                    }
                }

                // Label
                Native.NavigationContentDescription = Element.Label;

                // Opacity
                var opacity      = Element.Opacity;
                var finalOpacity = foregroundOpacity * opacity;
                var alpha        = (int)(finalOpacity * 255);
                Native.NavigationIcon?.SetAlpha(alpha);
            }
            else
            {
                Native.NavigationIcon = null;
                Native.NavigationContentDescription = null;
            }
        }
Exemplo n.º 14
0
        public static void SetTint(SeekBar seekBar, Color color)
        {
            ColorStateList s1 = ColorStateList.ValueOf(color);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                seekBar.ThumbTintList    = s1;
                seekBar.ProgressTintList = s1;
            }
            else if (Build.VERSION.SdkInt > BuildVersionCodes.GingerbreadMr1)
            {
                Drawable progressDrawable = DrawableCompat.Wrap(seekBar.ProgressDrawable);
                seekBar.ProgressDrawable = progressDrawable;
                DrawableCompat.SetTintList(progressDrawable, s1);
                if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBean)
                {
                    Drawable thumbDrawable = DrawableCompat.Wrap(seekBar.Thumb);
                    DrawableCompat.SetTintList(thumbDrawable, s1);
                    seekBar.SetThumb(thumbDrawable);
                }
            }
            else
            {
                PorterDuff.Mode mode = PorterDuff.Mode.SrcIn;
                if (Build.VERSION.SdkInt <= BuildVersionCodes.GingerbreadMr1)
                {
                    mode = PorterDuff.Mode.Multiply;
                }
                if (seekBar.IndeterminateDrawable != null)
                {
                    seekBar.IndeterminateDrawable.SetColorFilter(color, mode);
                }
                if (seekBar.ProgressDrawable != null)
                {
                    seekBar.ProgressDrawable.SetColorFilter(color, mode);
                }
            }
        }
        protected override void Render()
        {
            // IsInOverflow
            var showAsAction = Element.IsInOverflow
                                ? ShowAsAction.Never
                                : ShowAsAction.Always;

            Native.SetShowAsAction(showAsAction);

            // Label / String Content
            Native.SetTitle(Element.Label ?? (Element.Content is string contentLabel ? contentLabel : string.Empty));

            // Content & Icon
            if (!Element.IsInOverflow)             // We don't want to consider Icon or Content in overflow
            {
                // Icon
                switch (Element.Icon)
                {
                case BitmapIcon bitmap:
                    var drawable = DrawableHelper.FromUri(bitmap.UriSource);
                    Native.SetIcon(drawable);
                    break;

                default:
                    // Custom Content
                    switch (Element.Content)
                    {
                    case FrameworkElement content:
                        var currentParent = Element.GetParent();
                        _appBarButtonWrapper.Child = Element;

                        // Restore the original parent if any, as we
                        // want the DataContext to flow properly from the
                        // CommandBar.
                        Element.SetParent(currentParent);
                        if (content.Visibility == Visibility.Visible)
                        {
                            Native.SetActionView(_appBarButtonWrapper);
                        }
                        break;
                    }
                    break;
                }
            }

            // IsEnabled
            Native.SetEnabled(Element.IsEnabled);
            // According to the Material Design guidelines, the opacity inactive icons should be:
            // - Light background: 38%
            // - Dark background: 50%
            // Source: https://material.io/guidelines/style/icons.html
            // For lack of a reliable way to identify whether the background is light or dark,
            // we'll go with 50% opacity until this no longer satisfies projects requirements.
            var isEnabledOpacity = (Element.IsEnabled ? 1.0 : 0.5);

            // Visibility
            Native.SetVisible(Element.Visibility == Visibility.Visible);

            // Foreground
            var foreground        = Element.Foreground as SolidColorBrush;
            var foregroundColor   = foreground?.Color;
            var foregroundOpacity = foreground?.Opacity ?? 0;

            if (Native.Icon != null)
            {
                if (foreground != null)
                {
                    DrawableCompat.SetTint(Native.Icon, (Android.Graphics.Color)foregroundColor);
                }
                else
                {
                    DrawableCompat.SetTintList(Native.Icon, null);
                }
            }

            // Background
            var backgroundColor = (Element.Background as SolidColorBrush)?.ColorWithOpacity;

            if (backgroundColor != null)
            {
                _appBarButtonWrapper.SetBackgroundColor((Android.Graphics.Color)backgroundColor);
            }

            // Opacity
            var opacity      = Element.Opacity;
            var finalOpacity = isEnabledOpacity * foregroundOpacity * opacity;
            var alpha        = (int)(finalOpacity * 255);

            Native.Icon?.SetAlpha(alpha);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Internal method used to do the work on behalf of the UpdateColorProperty extension method for both
        /// XFGlossSwitchExtensions and XFGlossSwitchCompatExtensions
        /// </summary>
        /// <param name="control">Control.</param>
        /// <param name="properties">Properties.</param>
        /// <param name="propertyName">Property name.</param>
        /// <typeparam name="TControl">The 1st type parameter.</typeparam>
        static void ApplyColorProperty <TControl>(TControl control, ISwitchGloss properties, string propertyName)
        {
            // We have to create a multiple state color list to set both the "off" and "on" (checked/unchecked)
            // states of the switch control.

            bool isSwitch = Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.M &&
                            control is ASwitch;

            bool isSwitchCompat = !isSwitch &&
                                  XFGloss.Droid.Library.UsingAppCompat &&
                                  control is ASwitchCompat;

            Android.Content.Context controlContext = (isSwitch) ? (control as ASwitch).Context :
                                                     (isSwitchCompat) ? (control as ASwitchCompat).Context :
                                                     null;

            int[][] states = new int[2][];
            int[]   colors = new int[2];

            if (propertyName == null ||
                propertyName == SwitchGloss.TintColorProperty.PropertyName ||
                propertyName == SwitchGloss.OnTintColorProperty.PropertyName)
            {
                var tintColor   = properties.TintColor;
                var onTintColor = properties.OnTintColor;

                // Skip assigning anything if all properties are being applied and the color is set to the default value
                if (isSwitchCompat || propertyName != null || tintColor != Color.Default || onTintColor != Color.Default)
                {
                    var aTintColor = (tintColor != Color.Default) ?
                                     tintColor.ToAndroid() :
                                     new AColor(ThemeUtil.ColorControlNormal(controlContext,
                                                                             ThemeUtil.DefaultColorControlTrack));

                    var aOnTintColor = (onTintColor != Color.Default) ?
                                       onTintColor.ToAndroid() :
                                       new AColor(ThemeUtil.ColorControlActivated(controlContext,
                                                                                  ThemeUtil.DefaultColorControlTrackActivated));

                    // Clamp the track tint colors to 30% opacity - API 24 automatically does this. AppCompat doesn't.
                    if (isSwitchCompat && XFGloss.Droid.Library.UsingAppCompatAlpha)
                    {
                        aTintColor   = new AColor(aTintColor.R, aTintColor.G, aTintColor.B, (byte)77);
                        aOnTintColor = new AColor(aOnTintColor.R, aOnTintColor.G, aOnTintColor.B, (byte)77);
                    }

                    states[0] = new int[] { -Android.Resource.Attribute.StateChecked };
                    colors[0] = aTintColor;

                    states[1] = new int[] { Android.Resource.Attribute.StateChecked };
                    colors[1] = aOnTintColor;

                    var colorList = new ColorStateList(states, colors);

                    if (isSwitch)
                    {
                        (control as ASwitch).TrackTintList = colorList;
                    }
                    else if (isSwitchCompat)
                    {
                        DrawableCompat.SetTintList((control as ASwitchCompat).TrackDrawable, colorList);
                    }
                    else
                    {
                        Console.WriteLine(XFGloss.Droid.Library.appCompatWarning);
                    }
                }
            }

            if (propertyName == null ||
                propertyName == SwitchGloss.ThumbTintColorProperty.PropertyName ||
                propertyName == SwitchGloss.ThumbOnTintColorProperty.PropertyName)
            {
                var thumbTintColor   = properties.ThumbTintColor;
                var thumbOnTintColor = properties.ThumbOnTintColor;

                // Skip assigning anything if all properties are being applied and the color is set to the default value
                if (propertyName != null || thumbTintColor != Color.Default || thumbOnTintColor != Color.Default)
                {
                    states[0] = new int[] { -Android.Resource.Attribute.StateChecked };
                    colors[0] = (thumbTintColor != Color.Default) ?
                                thumbTintColor.ToAndroid() :
                                ThemeUtil.DefaultColorControlThumb;

                    states[1] = new int[] { Android.Resource.Attribute.StateChecked };
                    colors[1] = (thumbOnTintColor != Color.Default) ?
                                thumbOnTintColor.ToAndroid() :
                                new AColor(ThemeUtil.ColorControlActivated(controlContext,
                                                                           ThemeUtil.DefaultColorControlThumbActivated));

                    var colorList = new ColorStateList(states, colors);

                    if (isSwitch)
                    {
                        (control as ASwitch).ThumbTintList = colorList;
                    }
                    else if (isSwitchCompat)
                    {
                        DrawableCompat.SetTintList((control as ASwitchCompat).ThumbDrawable, colorList);
                    }
                    else
                    {
                        Console.WriteLine(XFGloss.Droid.Library.appCompatWarning);
                    }
                }
            }
        }
Exemplo n.º 17
0
 internal static void TintDrawable(this Drawable drawable, Color tintColor)
 {
     DrawableCompat.SetTint(drawable, tintColor);
     DrawableCompat.SetTintList(drawable, GetColorStates(tintColor));
 }
        protected override void Render()
        {
            // CommandBar::PrimaryCommands -> !IsInOverflow -> AsAction.Never -> displayed directly on command bar
            // CommandBar::SecondaryCommands -> IsInOverflow -> AsAction.Awalys -> (displayed as flyout menu items under [...])

            var native  = Native;
            var element = Element;

            // IsInOverflow
            var showAsAction = element.IsInOverflow
                                ? ShowAsAction.Never
                                : ShowAsAction.Always;

            native.SetShowAsAction(showAsAction);

            // (Icon ?? Content) and Label
            if (element.IsInOverflow)
            {
                native.SetActionView(null);
                native.SetIcon(null);
                native.SetTitle(element.Label);
            }
            else if (element.Icon != null)
            {
                switch (element.Icon)
                {
                case BitmapIcon bitmap:
                    var drawable = DrawableHelper.FromUri(bitmap.UriSource);
                    native.SetIcon(drawable);
                    break;

                case FontIcon font:                         // not supported
                case PathIcon path:                         // not supported
                case SymbolIcon symbol:                     // not supported
                default:
                    this.Log().WarnIfEnabled(() => $"{GetType().Name ?? "FontIcon, PathIcon and SymbolIcon"} are not supported. Use BitmapIcon instead with UriSource.");
                    native.SetIcon(null);
                    break;
                }
                native.SetActionView(null);
                native.SetTitle(null);
            }
            else
            {
                switch (element.Content)
                {
                case string text:
                    native.SetIcon(null);
                    native.SetActionView(null);
                    native.SetTitle(text);
                    break;

                case FrameworkElement fe:
                    var currentParent = element.GetParent();
                    _appBarButtonWrapper.Child = element;

                    //Restore the original parent if any, as we
                    // want the DataContext to flow properly from the
                    // CommandBar.
                    element.SetParent(currentParent);

                    native.SetIcon(null);
                    native.SetActionView(fe.Visibility == Visibility.Visible ? _appBarButtonWrapper : null);
                    native.SetTitle(null);
                    break;

                default:
                    native.SetIcon(null);
                    native.SetActionView(null);
                    native.SetTitle(null);
                    break;
                }
            }

            // IsEnabled
            native.SetEnabled(element.IsEnabled);
            // According to the Material Design guidelines, the opacity inactive icons should be:
            // - Light background: 38%
            // - Dark background: 50%
            // Source: https://material.io/guidelines/style/icons.html
            // For lack of a reliable way to identify whether the background is light or dark,
            // we'll go with 50% opacity until this no longer satisfies projects requirements.
            var isEnabledOpacity = (element.IsEnabled ? 1.0 : 0.5);

            // Visibility
            native.SetVisible(element.Visibility == Visibility.Visible);

            // Foreground
            var foreground        = element.Foreground as SolidColorBrush;
            var foregroundColor   = foreground?.Color;
            var foregroundOpacity = foreground?.Opacity ?? 0;

            if (native.Icon != null)
            {
                if (foreground != null)
                {
                    DrawableCompat.SetTint(native.Icon, (Android.Graphics.Color)foregroundColor);
                }
                else
                {
                    DrawableCompat.SetTintList(native.Icon, null);
                }
            }

            // Background
            var backgroundColor = (element.Background as SolidColorBrush)?.ColorWithOpacity;

            if (backgroundColor != null)
            {
                _appBarButtonWrapper.SetBackgroundColor((Android.Graphics.Color)backgroundColor);
            }

            // Opacity
            var opacity      = element.Opacity;
            var finalOpacity = isEnabledOpacity * foregroundOpacity * opacity;
            var alpha        = (int)(finalOpacity * 255);

            native.Icon?.SetAlpha(alpha);
        }