/// <summary> /// Gets the toolbar item drawable. /// </summary> /// <param name="toolbarItem">The toolbar item.</param> /// <param name="context">The context.</param> /// <returns></returns> private static Drawable GetToolbarItemDrawable(this ToolbarItem toolbarItem, Context context) { if (String.IsNullOrWhiteSpace(toolbarItem.Icon)) { return(null); } var iconItem = toolbarItem as IconToolbarItem; if (iconItem == null) { return(context.Resources.GetDrawable(toolbarItem.Icon)); } var drawable = new IconDrawable(context, iconItem.Icon); if (drawable == null) { return(null); } if (iconItem.IconColor != Xamarin.Forms.Color.Default) { drawable = drawable.Color(iconItem.IconColor.ToAndroid()); } return(drawable.ActionBarSize()); }
/// <summary> /// Updates the tabbed icons. /// </summary> private void UpdateTabbedIcons(Context context) { var tabLayout = FindViewById <TabLayout>(Iconize.TabLayoutId); if (tabLayout == null || tabLayout.TabCount == 0) { return; } for (var i = 0; i < tabLayout.TabCount; i++) { var tab = tabLayout.GetTabAt(i); if (_icons != null && i < _icons.Count) { var iconKey = _icons[i]; var icon = Iconize.FindIconForKey(iconKey); if (icon == null) { continue; } var drawable = new IconDrawable(context, icon).Color(Color.White.ToAndroid()).SizeDp(20); tab.SetIcon(drawable); } } }
private void UpdateImage() { var icon = Iconize.FindIconForKey(Image.Icon); if (icon == null) { #if USE_FASTRENDERERS SetImageResource(Android.Resource.Color.Transparent); #else Control.SetImageResource(Android.Resource.Color.Transparent); #endif return; } var iconSize = (Image.IconSize == IconImage.AutoSize ? Math.Max(Image.WidthRequest, Image.HeightRequest) : Image.IconSize); var drawable = new IconDrawable(Context, icon).Color(Image.IconColor.ToAndroid()) .SizeDp((Int32)iconSize); #if USE_FASTRENDERERS SetScaleType(Image.IconSize > 0 ? ScaleType.Center : ScaleType.FitCenter); SetImageDrawable(drawable); #else Control.SetScaleType(Image.IconSize > 0 ? ScaleType.Center : ScaleType.FitCenter); Control.SetImageDrawable(drawable); #endif }
/// <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); }