public static void SetTitleOrContentDescription(this IMenuItem Control, MenuItem Element) { if (Element == null) { return; } var elemValue = ConcatenateNameAndHint(Element); if (string.IsNullOrWhiteSpace(elemValue)) { elemValue = Element.AutomationId; } else if (!String.IsNullOrEmpty(Element.Text)) { elemValue = String.Join(". ", Element.Text, elemValue); } if (!string.IsNullOrWhiteSpace(elemValue)) { AMenuItemCompat.SetContentDescription(Control, elemValue); } }
protected override void UpdateMenuItemIcon(Context context, IMenuItem menuItem, ToolbarItem toolBarItem) { if (toolBarItem.Text == "BAD") { toolBarItem = new ToolbarItem { Text = "OK", IconImageSource = ImageSource.FromFile("heart.xml"), Order = toolBarItem.Order, Priority = toolBarItem.Priority }; if (toolBarItem.IconImageSource is FileImageSource fileImageSource) { var name = IOPath.GetFileNameWithoutExtension(fileImageSource.File); var id = ResourceManager.GetDrawableId(context, name); if (id != 0) { if ((int)Build.VERSION.SdkInt >= 21) { var drawable = context.GetDrawable(id); menuItem.SetIcon(drawable); } else { var drawable = Context.GetDrawable(name); menuItem.SetIcon(drawable); } AMenuItemCompat.SetContentDescription(menuItem, new Java.Lang.String("HEART")); return; } } } base.UpdateMenuItemIcon(context, menuItem, toolBarItem); }