Exemple #1
0
        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 = Path.GetFileNameWithoutExtension(fileImageSource.File);
                    var id   = Xamarin.Forms.Platform.Android.ResourceManager.GetDrawableByName(name);
                    if (id != 0)
                    {
                        var drawable = context.GetDrawable(id);
                        menuItem.SetIcon(drawable);
                        AMenuItemCompat.SetContentDescription(menuItem, new Java.Lang.String("HEART"));
                        return;
                    }
                }
            }

            base.UpdateMenuItemIcon(context, menuItem, toolBarItem);
        }
Exemple #2
0
        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);
            }
        }