void DrawMaterialStepperMinus(ICanvas canvas, RectF dirtyRect) { canvas.SaveState(); canvas.StrokeSize = 1; canvas.StrokeColor = GColor.FromArgb(Material.Color.Gray6); var x = dirtyRect.X + 1; var y = dirtyRect.Y; var height = MaterialStepperHeight; var width = MaterialStepperWidth / 2; canvas.DrawRoundedRectangle(x, y, width, height, 6); if (!IsEnabled) { canvas.FillColor = GColor.FromArgb(Material.Color.Gray1); canvas.FillRoundedRectangle(x, y, width, height, 6); } canvas.Translate(20, 20); var vBuilder = new PathBuilder(); var path = vBuilder.BuildPath(MaterialStepperMinusIcon); canvas.FillColor = GColor.FromArgb(Material.Color.Black); canvas.FillPath(path); canvas.RestoreState(); _minusRect = new RectF(x, y, width, height); }
void UpdateStatusBarColor(ShellAppearance appearance) { var activity = AndroidContext.GetActivity(); var window = activity?.Window; var decorView = window?.DecorView; int statusBarHeight = AndroidContext.GetStatusBarHeight(); int navigationBarHeight = AndroidContext.GetNavigationBarHeight(); // we are using the split drawable here to avoid GPU overdraw. // All it really is is a drawable that only draws under the statusbar/bottom bar to make sure // we dont draw over areas we dont need to. This has very limited benefits considering its // only saving us a flat color fill BUT it helps people not freak out about overdraw. AColor color; if (appearance != null) { color = appearance.BackgroundColor.ToPlatform(Color.FromArgb("#03A9F4")); } else { color = Color.FromArgb("#03A9F4").ToPlatform(); } if (!(decorView.Background is SplitDrawable splitDrawable) || splitDrawable.Color != color || splitDrawable.TopSize != statusBarHeight || splitDrawable.BottomSize != navigationBarHeight) { var split = new SplitDrawable(color, statusBarHeight, navigationBarHeight); decorView.SetBackground(split); } }
void UpdateBarBackgroundColor() { if (IsDisposed) { return; } if (IsBottomTabPlacement) { Color tintColor = Element.BarBackgroundColor; if (tintColor == null) { _bottomNavigationView.SetBackground(null); } else if (tintColor != null) { _bottomNavigationView.SetBackgroundColor(tintColor.ToAndroid()); } } else { Color tintColor = Element.BarBackgroundColor; if (tintColor == null) { _tabLayout.BackgroundTintMode = null; } else { _tabLayout.BackgroundTintMode = PorterDuff.Mode.Src; _tabLayout.BackgroundTintList = ColorStateList.ValueOf(tintColor.ToAndroid()); } } }
void DrawMaterialEditorBorder(ICanvas canvas, RectF dirtyRect) { canvas.SaveState(); var strokeWidth = 1.0f; canvas.FillColor = GColor.FromArgb(Material.Color.Black); if (View.IsFocused) { strokeWidth = 2.0f; canvas.FillColor = GColor.FromArgb(Material.Color.Blue); } var x = dirtyRect.X; //var y = 112.91f; var y = dirtyRect.Y + dirtyRect.Height - strokeWidth * 2; var width = dirtyRect.Width; var height = strokeWidth; canvas.FillRectangle(x, y, width, height); canvas.RestoreState(); }
void DrawMaterialActivityIndicator(ICanvas canvas, RectF dirtyRect) { canvas.SaveState(); float size = 40f; float strokeWidth = 4f; canvas.StrokeSize = strokeWidth; var x = dirtyRect.X; var y = dirtyRect.Y; if (View.IsRunning) { canvas.Rotate(MaterialActivityIndicatorRotate, x + strokeWidth + size / 2, y + strokeWidth + size / 2); canvas.StrokeColor = View.Color.ToGraphicsColor(Material.Color.Blue); canvas.DrawArc(x + strokeWidth, y + strokeWidth, size, size, MaterialActivityIndicatorStartAngle, MaterialActivityIndicatorStartAngle + MaterialActivityIndicatorSweepAngle, false, false); } else { canvas.Rotate(0, x + strokeWidth + size / 2, y + strokeWidth + size / 2); if (View.Color.IsDefault) { canvas.StrokeColor = GColor.FromArgb(Material.Color.LightBlue); } else { canvas.StrokeColor = View.Color.MultiplyAlpha(0.5).ToGraphicsColor(Material.Color.LightBlue); } canvas.DrawArc(x + strokeWidth, y + strokeWidth, size, size, 0, 360, false, false); } canvas.RestoreState(); }
static Color ResolveThemeColor(Color light, Color dark) { if (IsDarkTheme) { return(dark); } return(light); }
void DrawBackground(ICanvas canvas, RectF dirtyRect) { canvas.SaveState(); canvas.Antialias = true; canvas.FillColor = BackgroundColor; canvas.SetShadow(new SizeF(0, 0), 2, GColor.FromArgb(Material.Color.Gray6)); canvas.FillCircle(dirtyRect.Center, IconSize / 2f); canvas.RestoreState(); }
void UpdateStatusBarColor(ShellAppearance appearance) { Profile.FrameBegin("UpdtStatBarClr"); var activity = AndroidContext.GetActivity(); var window = activity?.Window; var decorView = window?.DecorView; var resources = AndroidContext.Resources; int statusBarHeight = 0; int resourceId = resources.GetIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { statusBarHeight = resources.GetDimensionPixelSize(resourceId); } int navigationBarHeight = 0; resourceId = resources.GetIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId > 0) { navigationBarHeight = resources.GetDimensionPixelSize(resourceId); } // TODO Previewer Hack if (decorView != null) { // we are using the split drawable here to avoid GPU overdraw. // All it really is is a drawable that only draws under the statusbar/bottom bar to make sure // we dont draw over areas we dont need to. This has very limited benefits considering its // only saving us a flat color fill BUT it helps people not freak out about overdraw. AColor color; if (appearance != null) { color = appearance.BackgroundColor.ToAndroid(Color.FromHex("#03A9F4")); } else { color = Color.FromHex("#03A9F4").ToAndroid(); } if (!(decorView.Background is SplitDrawable splitDrawable) || splitDrawable.Color != color || splitDrawable.TopSize != statusBarHeight || splitDrawable.BottomSize != navigationBarHeight) { Profile.FramePartition("Create SplitDrawable"); var split = new SplitDrawable(color, statusBarHeight, navigationBarHeight); Profile.FramePartition("SetBackground"); decorView.SetBackground(split); } } Profile.FrameEnd("UpdtStatBarClr"); }
protected virtual ColorStateList GetItemTextColorStates() { if (IsDisposed) { return(null); } if (_originalTabTextColors == null) { _originalTabTextColors = (IsBottomTabPlacement) ? _bottomNavigationView.ItemTextColor : _tabLayout.TabTextColors; } Color barItemColor = BarItemColor; Color barTextColor = Element.BarTextColor; Color barSelectedItemColor = BarSelectedItemColor; if (barItemColor == null && barTextColor == null && barSelectedItemColor == null) { return(_originalTabTextColors); } if (_newTabTextColors != null) { return(_newTabTextColors); } int checkedColor; int defaultColor; if (barTextColor != null) { checkedColor = barTextColor.ToAndroid().ToArgb(); defaultColor = checkedColor; } else { defaultColor = barItemColor.ToAndroid().ToArgb(); if (barItemColor == null && _originalTabTextColors != null) { defaultColor = _originalTabTextColors.DefaultColor; } checkedColor = defaultColor; if (barSelectedItemColor != null) { checkedColor = barSelectedItemColor.ToAndroid().ToArgb(); } } _newTabTextColors = GetColorStateList(defaultColor, checkedColor); return(_newTabTextColors); }
void UpdateBackgroundColor() { if (_disposed) { return; } Color bgColor = Element.BackgroundColor; _backgroundDrawable.SetColor(bgColor?.ToAndroid() ?? AColor.White); }
protected virtual ColorStateList GetItemIconTintColorState() { if (IsDisposed) { return(null); } if (IsBottomTabPlacement) { if (_orignalTabIconColors == null) { _orignalTabIconColors = _bottomNavigationView.ItemIconTintList; } } // this ensures that existing behavior doesn't change else if (!IsBottomTabPlacement && BarSelectedItemColor != null && BarItemColor == null) { return(null); } Color barItemColor = BarItemColor; Color barSelectedItemColor = BarSelectedItemColor; if (barItemColor == null && barSelectedItemColor == null) { return(_orignalTabIconColors); } if (_newTabIconColors != null) { return(_newTabIconColors); } int defaultColor = barItemColor.ToAndroid().ToArgb(); if (barItemColor == null && _orignalTabIconColors != null) { defaultColor = _orignalTabIconColors.DefaultColor; } int checkedColor = defaultColor; if (barSelectedItemColor != null) { checkedColor = barSelectedItemColor.ToAndroid().ToArgb(); } _newTabIconColors = GetColorStateList(defaultColor, checkedColor); return(_newTabIconColors); }
void DrawMaterialProgressTrack(ICanvas canvas, RectF dirtyRect) { canvas.SaveState(); canvas.FillColor = GColor.FromArgb(Fluent.Color.Background.NeutralLight); var x = dirtyRect.X; var y = (float)((dirtyRect.Height - MaterialTrackHeight) / 2); var width = dirtyRect.Width; canvas.FillRectangle(x, y, width, MaterialTrackHeight); canvas.RestoreState(); }
public static void OnToolbarItemPropertyChanged( this AToolbar toolbar, PropertyChangedEventArgs e, ToolbarItem toolbarItem, ICollection <ToolbarItem> toolbarItems, Context context, Color tintColor, PropertyChangedEventHandler toolbarItemChanged, List <IMenuItem> currentMenuItems, List <ToolbarItem> currentToolbarItems, Action <Context, IMenuItem, ToolbarItem> updateMenuItemIcon = null) { if (toolbarItems == null) { return; } if (!e.IsOneOf(MenuItem.TextProperty, MenuItem.IconImageSourceProperty, MenuItem.IsEnabledProperty)) { return; } int index = 0; foreach (var item in toolbarItems) { if (item == toolbarItem) { break; } index++; } if (index >= currentMenuItems.Count) { return; } if (currentMenuItems[index].IsAlive()) { UpdateMenuItem(toolbar, toolbarItem, index, context, tintColor, toolbarItemChanged, currentMenuItems, currentToolbarItems, updateMenuItemIcon); } else { UpdateMenuItems(toolbar, toolbarItems, context, tintColor, toolbarItemChanged, currentMenuItems, currentToolbarItems, updateMenuItemIcon); } }
public StepperDrawable(IStepper view) { _minusRippleEffect = new RippleEffectDrawable { RippleColor = GColor.FromArgb(Material.Color.Gray6) }; _plusRippleEffect = new RippleEffectDrawable { RippleColor = GColor.FromArgb(Material.Color.Gray6) }; _minusRippleEffect.Invalidated += (s, e) => SendInvalidated(); _plusRippleEffect.Invalidated += (s, e) => SendInvalidated(); View = view; }
void UpdateBorderColor() { if (_disposed) { return; } Color borderColor = Element.BorderColor; if (borderColor == null) { _backgroundDrawable.SetStroke(0, AColor.Transparent); } else { _backgroundDrawable.SetStroke(3, borderColor.ToAndroid()); } }
public static void UpdateMenuItems(this AToolbar toolbar, IEnumerable <ToolbarItem> sortedToolbarItems, IMauiContext mauiContext, Color tintColor, PropertyChangedEventHandler toolbarItemChanged, List <IMenuItem> previousMenuItems, List <ToolbarItem> previousToolBarItems, Action <Context, IMenuItem, ToolbarItem> updateMenuItemIcon = null) { if (sortedToolbarItems == null || previousMenuItems == null) { return; } var context = mauiContext.Context; var menu = toolbar.Menu; foreach (var toolbarItem in previousToolBarItems) { toolbarItem.PropertyChanged -= toolbarItemChanged; } int i = 0; foreach (var item in sortedToolbarItems) { UpdateMenuItem(toolbar, item, i, mauiContext, tintColor, toolbarItemChanged, previousMenuItems, previousToolBarItems, updateMenuItemIcon); i++; } int toolBarItemCount = i; while (toolBarItemCount < previousMenuItems.Count) { menu.RemoveItem(previousMenuItems[toolBarItemCount].ItemId); previousMenuItems[toolBarItemCount].Dispose(); previousMenuItems.RemoveAt(toolBarItemCount); } previousToolBarItems.Clear(); previousToolBarItems.AddRange(sortedToolbarItems); }
void DrawMaterialCheckBoxBackground(ICanvas canvas, RectF dirtyRect) { canvas.SaveState(); float size = 18f; var x = dirtyRect.X; var y = dirtyRect.Y; if (dirtyRect.Height > size) { y += (dirtyRect.Height - size) / 2; } if (IsEnabled) { if (View.IsChecked) { canvas.FillColor = View.Color.ToGraphicsColor(Material.Color.Blue); canvas.FillRoundedRectangle(x, y, size, size, 2); } else { var strokeWidth = 2; canvas.StrokeSize = strokeWidth; canvas.StrokeColor = View.Color.ToGraphicsColor(Material.Color.Gray1); canvas.DrawRoundedRectangle(x + strokeWidth / 2, y + strokeWidth / 2, size - strokeWidth, size - strokeWidth, 2); } } else { var strokeWidth = 2; canvas.FillColor = GColor.FromArgb(Material.Color.Gray2); canvas.FillRoundedRectangle(x, y, size, size, 2); canvas.StrokeSize = strokeWidth; canvas.StrokeColor = GColor.FromArgb(Material.Color.Gray1); canvas.DrawRoundedRectangle(x + strokeWidth / 2, y + strokeWidth / 2, size - strokeWidth, size - strokeWidth, 2); } canvas.RestoreState(); }
void DrawMaterialButtonBackground(ICanvas canvas, RectF dirtyRect) { canvas.SaveState(); canvas.FillColor = IsEnabled ? View.BackgroundColor.ToGraphicsColor(Material.Color.Blue) : GColor.FromArgb(Material.Color.Gray1); var x = dirtyRect.X; var y = dirtyRect.Y; var width = dirtyRect.Width - MaterialShadowOffset; var height = MaterialBackgroundHeight - MaterialShadowOffset; canvas.SetShadow(new SizeF(0, 1), 3, GColor.FromArgb(Material.Color.Gray2)); canvas.FillRoundedRectangle(x, y, width, height, (float)View.CornerRadius); canvas.RestoreState(); _backgroundRect = new RectF(x, y, width, height); }
internal void UpdateTabItemStyle() { Color barItemColor = BarItemColor; Color barTextColor = Element.BarTextColor; Color barSelectedItemColor = BarSelectedItemColor; if (_tabItemStyleLoaded && _currentBarItemColor == barItemColor && _currentBarTextColor == barTextColor && _currentBarSelectedItemColor == barSelectedItemColor) { return; } _tabItemStyleLoaded = true; _currentBarItemColor = BarItemColor; _currentBarTextColor = Element.BarTextColor; _currentBarSelectedItemColor = BarSelectedItemColor; UpdateBarTextColor(); UpdateItemIconColor(); }
public static void UpdateMenuItems(this AToolbar toolbar, IEnumerable <ToolbarItem> sortedToolbarItems, Context context, Color tintColor, PropertyChangedEventHandler toolbarItemChanged, List <IMenuItem> menuItemsCreated, List <ToolbarItem> toolbarItemsCreated, Action <Context, IMenuItem, ToolbarItem> updateMenuItemIcon = null) { if (sortedToolbarItems == null || menuItemsCreated == null) { return; } var menu = toolbar.Menu; menu.Clear(); foreach (var menuItem in menuItemsCreated) { menuItem.Dispose(); } foreach (var toolbarItem in toolbarItemsCreated) { toolbarItem.PropertyChanged -= toolbarItemChanged; } menuItemsCreated.Clear(); toolbarItemsCreated.Clear(); foreach (var item in sortedToolbarItems) { UpdateMenuItem(toolbar, item, null, context, tintColor, toolbarItemChanged, menuItemsCreated, toolbarItemsCreated, updateMenuItemIcon); } }
public static void UpdateBackground(this GradientDrawable gradientDrawable, Brush brush, int height, int width) { if (gradientDrawable == null || brush == null || brush.IsEmpty) { return; } if (brush is SolidColorBrush solidColorBrush) { Color bgColor = solidColorBrush.Color; gradientDrawable.SetColor(bgColor?.ToAndroid() ?? Colors.Transparent.ToAndroid()); } if (brush is LinearGradientBrush linearGradientBrush) { var p1 = linearGradientBrush.StartPoint; var x1 = (float)p1.X; var y1 = (float)p1.Y; var p2 = linearGradientBrush.EndPoint; var x2 = (float)p2.X; var y2 = (float)p2.Y; const double Rad2Deg = 180.0 / Math.PI; float xDiff = x2 - x1; float yDiff = y2 - y1; double angle = Math.Atan2(yDiff, xDiff) * Rad2Deg; if (angle < 0) { angle += 360; } var gradientBrushData = linearGradientBrush.GetGradientBrushData(); var colors = gradientBrushData.Item1; if (colors.Length < 2) { return; } gradientDrawable.SetGradientType(GradientType.LinearGradient); gradientDrawable.SetColors(colors); SetGradientOrientation(gradientDrawable, angle); } if (brush is RadialGradientBrush radialGradientBrush) { var center = radialGradientBrush.Center; float centerX = (float)center.X; float centerY = (float)center.Y; float radius = (float)radialGradientBrush.Radius; var gradientBrushData = radialGradientBrush.GetGradientBrushData(); var colors = gradientBrushData.Item1; if (colors.Length < 2) { return; } gradientDrawable.SetGradientType(GradientType.RadialGradient); gradientDrawable.SetGradientCenter(centerX, centerY); gradientDrawable.SetGradientRadius(Math.Max(height, width) * radius); gradientDrawable.SetColors(colors); } }
protected virtual void DrawMaterialSliderTrackProgress(ICanvas canvas, RectF dirtyRect) { canvas.SaveState(); canvas.FillColor = IsEnabled ? View.MinimumTrackColor.ToGraphicsColor(Material.Color.Blue) : GColor.FromArgb(Material.Color.Gray1); var x = dirtyRect.X; var value = ((double)ValueRate).Clamp(0, 1); var width = (float)(dirtyRect.Width * value); var height = 2; var y = (float)((dirtyRect.Height - height) / 2); canvas.FillRoundedRectangle(x, y, width, height, 0); canvas.RestoreState(); }
protected virtual void DrawMaterialSliderThumb(ICanvas canvas, RectF dirtyRect) { canvas.SaveState(); var value = ((double)ValueRate).Clamp(0, 1); var x = (float)((dirtyRect.Width * value) - (MaterialFloatThumb / 2)); if (x <= 0) { x = 0; } if (x >= dirtyRect.Width - MaterialFloatThumb) { x = dirtyRect.Width - MaterialFloatThumb; } var y = (float)((dirtyRect.Height - MaterialFloatThumb) / 2); canvas.FillColor = IsEnabled ? View.ThumbColor.ToGraphicsColor(Material.Color.Blue) : GColor.FromArgb(Material.Color.Gray1); canvas.FillEllipse(x, y, MaterialFloatThumb, MaterialFloatThumb); canvas.RestoreState(); ThumbRect = new RectF(x, y, MaterialFloatThumb, MaterialFloatThumb); }
void DrawMaterialSliderTrackBackground(ICanvas canvas, RectF dirtyRect) { canvas.SaveState(); canvas.FillColor = IsEnabled ? View.MaximumTrackColor.ToGraphicsColor(Material.Color.LightBlue) : GColor.FromArgb(Material.Color.Gray1); var x = dirtyRect.X; var width = dirtyRect.Width; var height = 2; var y = (float)((dirtyRect.Height - height) / 2); canvas.FillRoundedRectangle(x, y, width, height, 0); canvas.RestoreState(); TrackRect = new RectF(x, y, width, height); }
internal static void UpdateMenuItemIcon(IMauiContext mauiContext, IMenuItem menuItem, ToolbarItem toolBarItem, Color tintColor) { ImageSourceLoader.LoadImage(toolBarItem, mauiContext, result => { var baseDrawable = result.Value; if (menuItem == null || !menuItem.IsAlive()) { return; } if (baseDrawable != null) { using (var constant = baseDrawable.GetConstantState()) using (var newDrawable = constant.NewDrawable()) using (var iconDrawable = newDrawable.Mutate()) { if (tintColor != null) { iconDrawable.SetColorFilter(tintColor.ToNative(Colors.White), FilterMode.SrcAtop); } if (!menuItem.IsEnabled) { iconDrawable.Mutate().SetAlpha(DefaultDisabledToolbarAlpha); } menuItem.SetIcon(iconDrawable); } } }); }
internal static void UpdateMenuItem(AToolbar toolbar, ToolbarItem item, int?menuItemIndex, Context context, Color tintColor, PropertyChangedEventHandler toolbarItemChanged, List <IMenuItem> menuItemsCreated, List <ToolbarItem> toolbarItemsCreated, Action <Context, IMenuItem, ToolbarItem> updateMenuItemIcon = null) { IMenu menu = toolbar.Menu; item.PropertyChanged -= toolbarItemChanged; item.PropertyChanged += toolbarItemChanged; IMenuItem menuitem; Java.Lang.ICharSequence newTitle = null; if (!String.IsNullOrWhiteSpace(item.Text)) { if (item.Order != ToolbarItemOrder.Secondary && tintColor != null && tintColor != null) { var color = item.IsEnabled ? tintColor.ToAndroid() : tintColor.MultiplyAlpha(0.302f).ToAndroid(); SpannableString titleTinted = new SpannableString(item.Text); titleTinted.SetSpan(new ForegroundColorSpan(color), 0, titleTinted.Length(), 0); newTitle = titleTinted; } else { newTitle = new Java.Lang.String(item.Text); } } else { newTitle = new Java.Lang.String(); } if (menuItemIndex == null) { menuitem = menu.Add(0, AppCompat.Platform.GenerateViewId(), 0, newTitle); menuItemsCreated?.Add(menuitem); toolbarItemsCreated?.Add(item); } else { if (menuItemsCreated == null || menuItemsCreated.Count < menuItemIndex.Value) { return; } menuitem = menuItemsCreated[menuItemIndex.Value]; if (!menuitem.IsAlive()) { return; } menuitem.SetTitle(newTitle); } menuitem.SetEnabled(item.IsEnabled); menuitem.SetTitleOrContentDescription(item); if (updateMenuItemIcon != null) { updateMenuItemIcon(context, menuitem, item); } else { UpdateMenuItemIcon(context, menuitem, item, tintColor); } if (item.Order != ToolbarItemOrder.Secondary) { menuitem.SetShowAsAction(ShowAsAction.Always); } menuitem.SetOnMenuItemClickListener(new GenericMenuClickListener(((IMenuItemController)item).Activate)); if (item.Order != ToolbarItemOrder.Secondary && !Forms.IsOreoOrNewer && (tintColor != null && tintColor != null)) { var view = toolbar.FindViewById(menuitem.ItemId); if (view is ATextView textView) { if (item.IsEnabled) { textView.SetTextColor(tintColor.ToAndroid()); } else { textView.SetTextColor(tintColor.MultiplyAlpha(0.302f).ToAndroid()); } } } }
public void SetElement(TElement element) { TElement oldElement = Element; Element = element ?? throw new ArgumentNullException(nameof(element)); Performance.Start(out string reference); if (oldElement != null) { oldElement.PropertyChanged -= _propertyChangeHandler; } Color currentColor = oldElement?.BackgroundColor ?? null; if (element.BackgroundColor != currentColor) { UpdateBackgroundColor(); } if (element.Background != null) { UpdateBackground(); } if (_propertyChangeHandler == null) { _propertyChangeHandler = OnElementPropertyChanged; } element.PropertyChanged += _propertyChangeHandler; if (oldElement == null) { SoundEffectsEnabled = false; } OnElementChanged(new ElementChangedEventArgs <TElement>(oldElement, element)); if (AutoPackage && _packager == null) { SetPackager(new VisualElementPackager(this)); } if (AutoTrack && Tracker == null) { SetTracker(new VisualElementTracker(this)); } if (oldElement != null) { Tracker?.UpdateLayout(); } if (element != null) { SendVisualElementInitialized(element, this); } EffectUtilities.RegisterEffectControlProvider(this, oldElement, element); if (!string.IsNullOrEmpty(element.AutomationId)) { SetAutomationId(element.AutomationId); } SetContentDescription(); SetFocusable(); UpdateInputTransparent(); UpdateInputTransparentInherited(); UpdateTabStop(); UpdateTabIndex(); Performance.Stop(reference); }
internal static void UpdateMenuItemIcon(Context context, IMenuItem menuItem, ToolbarItem toolBarItem, Color tintColor) { _ = context.ApplyDrawableAsync(toolBarItem, MenuItem.IconImageSourceProperty, baseDrawable => { if (menuItem == null || !menuItem.IsAlive()) { return; } if (baseDrawable != null) { using (var constant = baseDrawable.GetConstantState()) using (var newDrawable = constant.NewDrawable()) using (var iconDrawable = newDrawable.Mutate()) { if (tintColor != null) { iconDrawable.SetColorFilter(tintColor.ToAndroid(Colors.White), FilterMode.SrcAtop); } if (!menuItem.IsEnabled) { iconDrawable.Mutate().SetAlpha(DefaultDisabledToolbarAlpha); } menuItem.SetIcon(iconDrawable); } } }); }
void UpdateToolbar() { if (_disposed) { return; } Context context = Context; AToolbar bar = _toolbar; ActionBarDrawerToggle toggle = _drawerToggle; if (bar == null) { return; } bool isNavigated = NavigationPageController.StackDepth > 1; bar.NavigationIcon = null; Page currentPage = Element.CurrentPage; if (isNavigated) { if (NavigationPage.GetHasBackButton(currentPage)) { if (toggle != null) { toggle.DrawerIndicatorEnabled = false; toggle.SyncState(); } var icon = new DrawerArrowDrawable(context.GetThemedContext()); icon.Progress = 1; bar.NavigationIcon = icon; var prevPage = Element.Peek(1); var backButtonTitle = NavigationPage.GetBackButtonTitle(prevPage); _defaultNavigationContentDescription = backButtonTitle != null ? bar.SetNavigationContentDescription(prevPage, backButtonTitle) : bar.SetNavigationContentDescription(prevPage, _defaultNavigationContentDescription); } else if (toggle != null && _flyoutPage != null) { toggle.DrawerIndicatorEnabled = _flyoutPage.ShouldShowToolbarButton(); toggle.SyncState(); } } else { if (toggle != null && _flyoutPage != null) { toggle.DrawerIndicatorEnabled = _flyoutPage.ShouldShowToolbarButton(); toggle.SyncState(); } } Color tintColor = Element.BarBackgroundColor; if (tintColor == null) { bar.BackgroundTintMode = null; } else { bar.BackgroundTintMode = PorterDuff.Mode.Src; bar.BackgroundTintList = ColorStateList.ValueOf(tintColor.ToAndroid()); } Brush barBackground = Element.BarBackground; bar.UpdateBackground(barBackground); Color textColor = Element.BarTextColor; if (textColor != null) { bar.SetTitleTextColor(textColor.ToAndroid().ToArgb()); } Color navIconColor = NavigationPage.GetIconColor(Current); if (navIconColor != null && bar.NavigationIcon != null) { bar.NavigationIcon.SetColorFilter(navIconColor, FilterMode.SrcAtop); } bar.Title = currentPage?.Title ?? string.Empty; if (_toolbar.NavigationIcon != null && textColor != null) { var icon = _toolbar.NavigationIcon as DrawerArrowDrawable; if (icon != null) { icon.Color = textColor.ToAndroid().ToArgb(); } } UpdateTitleIcon(); UpdateTitleView(); }
void UpdateBarBackgroundColor() { if (IsDisposed) { return; } if (IsBottomTabPlacement) { Color tintColor = Element.BarBackgroundColor; if (tintColor == null) { _bottomNavigationView.SetBackground(null); } else if (tintColor != null) { _bottomNavigationView.SetBackgroundColor(tintColor.ToAndroid()); } } else { Color tintColor = Element.BarBackgroundColor; if (Forms.IsLollipopOrNewer) { if (tintColor == null) { _tabLayout.BackgroundTintMode = null; } else { _tabLayout.BackgroundTintMode = PorterDuff.Mode.Src; _tabLayout.BackgroundTintList = ColorStateList.ValueOf(tintColor.ToAndroid()); } } else { if (tintColor == null && _backgroundDrawable != null) { _tabLayout.SetBackground(_backgroundDrawable); } else if (tintColor != null) { // 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()); } } } }