protected virtual async void SetupMenu(IMenu menu, int maxBottomItems, ShellItem shellItem) { menu.Clear(); bool showMore = ShellItem.Items.Count > maxBottomItems; int end = showMore ? maxBottomItems - 1 : ShellItem.Items.Count; var currentIndex = shellItem.Items.IndexOf(ShellSection); List <IMenuItem> menuItems = new List <IMenuItem>(); List <Task> loadTasks = new List <Task>(); for (int i = 0; i < end; i++) { var item = shellItem.Items[i]; using (var title = new Java.Lang.String(item.Title)) { var menuItem = menu.Add(0, i, 0, title); menuItems.Add(menuItem); loadTasks.Add(SetMenuItemIcon(menuItem, item.Icon)); UpdateShellSectionEnabled(item, menuItem); if (item == ShellSection) { menuItem.SetChecked(true); } } } if (showMore) { var moreString = new Java.Lang.String("More"); var menuItem = menu.Add(0, MoreTabId, 0, moreString); moreString.Dispose(); menuItem.SetIcon(Resource.Drawable.abc_ic_menu_overflow_material); if (currentIndex >= maxBottomItems - 1) { menuItem.SetChecked(true); } } _bottomView.Visibility = end == 1 ? ViewStates.Gone : ViewStates.Visible; _bottomView.SetShiftMode(false, false); if (loadTasks.Count > 0) { await Task.WhenAll(loadTasks); } foreach (var menuItem in menuItems) { menuItem.Dispose(); } }
public override void OnCreateOptionsMenu(IMenu menu, MenuInflater inflater) { if (menu == null) { return; } menu.Clear(); if (Menu.ButtonCount > 1 && Build.VERSION.SdkInt <= BuildVersionCodes.JellyBean) { var itemId = (int)OutputPane * byte.MaxValue; var item = menu.Add((int)OutputPane, itemId, (int)OutputPane, Device.Resources.GetString("Menu")); item.SetShowAsAction(ShowAsAction.Always); const string source = "ic_menu_dark.png"; ImageGetter.SetDrawable(source, (bitmap, url) => { if (url == source) { item.SetIcon(bitmap); } }); } else if (_buttons != null && _buttons.Length > 0 && _buttons[0]?.Item != null) { foreach (var button in _buttons) { button.Item = menu.Add((int)OutputPane, button.Item.ItemId, (int)OutputPane, button.Title); } } else { var showIfRoom = true; _buttons = Enumerable.Range(0, Menu.ButtonCount).Select(i => { var menuItem = Menu.GetButton(i); if (menuItem is UI.IMenu) { showIfRoom = false; } return(menuItem as MenuButton ?? menuItem?.Pair as MenuButton); }).ToArray(); var subCount = 0; for (int i = 0; i < _buttons.Length; i++) { var button = _buttons[i]; var menuId = button is IMenu ? subCount++ : (int)OutputPane; button.AddToParent(menu, menuId, i, showIfRoom); } } base.OnCreateOptionsMenu(menu, inflater); }
public override bool OnCreateOptionsMenu(Android.Views.IMenu menu) { if (WhiteLabelConfig.EXTERNAL_LINKS) { var actionItem1 = menu.Add(Resource.String.help); MenuItemCompat.SetShowAsAction(actionItem1, MenuItemCompat.ShowAsActionNever); } var actionItem2 = menu.Add(0, 88, 1, Resource.String.opensource); MenuItemCompat.SetShowAsAction(actionItem2, MenuItemCompat.ShowAsActionNever); return(base.OnCreateOptionsMenu(menu)); }
public static bool CreateOptionsMenu(this Context context, IParentMenu parentMenu, Android.Views.IMenu menu) { if (parentMenu == null) { return(false); } #warning TODO - make this OO - let the _parentMenu render itself... foreach (var child in parentMenu.Children) { var childCast = child as CaptionAndIconMenu; if (childCast != null) { var item = menu.Add(1, childCast.UniqueId, 0, childCast.Caption); if (!string.IsNullOrEmpty(childCast.Icon)) { #warning TODO - cannot use Resourcein library code! Should we use reflection here? Or some other mechaniasm? var resourceId = context.Resources.GetIdentifier(childCast.Icon, "drawable", context.PackageName); if (resourceId > 0) { item.SetIcon(resourceId); } } } } return(true); }
public override bool OnCreateOptionsMenu(Android.Views.IMenu menu) { var editItem = menu.Add(0, EDIT_BTN_ID, 0, "Edit"); editItem.SetShowAsAction(ShowAsAction.Always); return(base.OnCreateOptionsMenu(menu)); }
public virtual void AddToParent(Android.Views.IMenu parent, int menuId, int index, bool showIfRoom) { var itemId = menuId * byte.MaxValue + index; ShowAsAction = showIfRoom ? ShowAsAction.IfRoom : ShowAsAction.Never; Item = parent.Add(menuId, itemId, menuId, Title); }
public override void OnCreateOptionsMenu(Android.Views.IMenu menu, Android.Views.MenuInflater inflater) { var typedValue = new TypedValue(); Activity.Theme.ResolveAttribute(Resource.Attribute.app_map_ic_map, typedValue, true); var mapMenuItem = menu.Add(0, MENU_MAP_ID, 0, new Java.Lang.String(LocalizationService.GetLocalizableString(MapConstants.RESX_NAME, "Map_Title"))); mapMenuItem.SetIcon(Resources.GetDrawable(typedValue.ResourceId, Context.Theme)); mapMenuItem.SetShowAsAction(ShowAsAction.Always); }
public override bool OnCreateOptionsMenu(Android.Views.IMenu menu) { if (WhiteLabelConfig.EXTERNAL_LINKS) { var actionItem1 = menu.Add(Resource.String.help); MenuItemCompat.SetShowAsAction(actionItem1, MenuItemCompat.ShowAsActionNever); } if (WhiteLabelConfig.OFFLINE_CACHE) { var actionItem2 = menu.Add(0, 88, 0, Resource.String.cache); MenuItemCompat.SetShowAsAction(actionItem2, MenuItemCompat.ShowAsActionNever); #if DEBUG var actionItem3 = menu.Add(0, 99, 0, "Fix Missing"); MenuItemCompat.SetShowAsAction(actionItem3, MenuItemCompat.ShowAsActionNever); #endif } return(true); }
public override bool OnCreateOptionsMenu(IMenu menu) { int group = 0; IMenuItem item1 = menu.Add(group, SWAP_MENU, SWAP_MENU, "Swap Language"); item1.SetIcon(Resource.Drawable.swap); item1.SetShowAsAction(ShowAsAction.Never | ShowAsAction.WithText); IMenuItem item2 = menu.Add(group, PINYIN_MENU, PINYIN_MENU, "Pinyin Toggle"); item2.SetIcon(Resource.Drawable.pinyin); item2.SetShowAsAction(ShowAsAction.IfRoom); //IMenuItem item3 = menu.Add(group, SYNC_MENU, SYNC_MENU, "Sync"); //item3.SetShowAsAction(ShowAsAction.Never | ShowAsAction.WithText); IMenuItem item4 = menu.Add(group, SETTINGS_MENU, SETTINGS_MENU, "Settings"); item4.SetShowAsAction(ShowAsAction.Never | ShowAsAction.WithText); return(base.OnCreateOptionsMenu(menu)); }