Exemplo n.º 1
0
        public static void UpdateBarTextColor(this AToolbar nativeToolbar, Toolbar toolbar)
        {
            var textColor = toolbar.BarTextColor;

            // Because we use the same toolbar across multiple navigation pages (think tabbed page with nested NavigationPage)
            // We need to reset the toolbar text color to the default color when it's unset
            if (_defaultTitleTextColor == null)
            {
                var context = nativeToolbar.Context?.GetThemedContext();
                _defaultTitleTextColor = PlatformInterop.GetColorStateListForToolbarStyleableAttribute(context,
                                                                                                       Resource.Attribute.toolbarStyle, Resource.Styleable.Toolbar_titleTextColor);
            }

            if (textColor != null)
            {
                nativeToolbar.SetTitleTextColor(textColor.ToPlatform().ToArgb());
            }
            else if (_defaultTitleTextColor != null)
            {
                nativeToolbar.SetTitleTextColor(_defaultTitleTextColor);
            }

            if (nativeToolbar.NavigationIcon is DrawerArrowDrawable icon)
            {
                if (textColor != null)
                {
                    _defaultNavigationIconColor = icon.Color;
                    icon.Color = textColor.ToPlatform().ToArgb();
                }
                else if (_defaultNavigationIconColor != null)
                {
                    icon.Color = _defaultNavigationIconColor.Value;
                }
            }
        }