Class ContextualToolbarMenuItem

    • Constructor Detail

    • Method Detail

      • setIcon

         void setIcon(@NonNull() Drawable icon)

        Sets the icon to be used for the menu item.

        Parameters:
        icon - Drawable used as the menu icon.
      • setTitle

         void setTitle(@NonNull() String title)

        Sets the title for the menu item.

        Parameters:
        title - Title to assign to the menu item.
      • getIconColor

        @ColorInt() int getIconColor()

        Gets the default color of the menu icon.

        Returns:

        Menu item color (tint).

      • setIconColor

         void setIconColor(@ColorInt() int iconColor)

        Sets the default color for the menu icon.

        Parameters:
        iconColor - Default menu icon color.
      • getIconColorActivated

        @ColorInt() int getIconColorActivated()

        Gets the color for the icon when activated (if the item is selectable).

        Returns:

        Menu item color (tint) when activated.

      • setIconColorActivated

         void setIconColorActivated(@ColorInt() int iconColorActivated)

        Sets the color for the icon when activated (if the item is selectable).

        Parameters:
        iconColorActivated - Background circle color when the item is activated.
      • isSelectable

         boolean isSelectable()

        Indicates whether the item is selectable, or just clickable.

        Returns:

        true is menu item is selectable, false if it's only clickable.

      • setSelectable

         void setSelectable(boolean selectable)

        Sets if item is selectable or not.

        Parameters:
        selectable - If true, the item can be selected/activated, otherwise it's just clickable.
      • isTextItemFirstFromEnd

         boolean isTextItemFirstFromEnd()

        Gets whether the item is a text button and the first from the end

        Returns:

        boolean to check whether its the first text item or not

      • setTextItemFirstFromEnd

         void setTextItemFirstFromEnd(boolean isTextItemFirstFromEnd)

        Sets whether the item is a text button and the first from the end

        Parameters:
        isTextItemFirstFromEnd - boolean to check whether its the first text item or not
      • getUseAlternateBackground

         boolean getUseAlternateBackground()

        Returns true, if this menu item triggers a background change on the toolbar. Only applied for menu items with position == Position.END

      • setUseAlternateBackground

         void setUseAlternateBackground(boolean useAlternateBackground)

        See useAlternateBackground for a description.

        Parameters:
        useAlternateBackground - true if this item should trigger a change of the background color in the toolbar
      • setDefaultSelectedMenuItem

         void setDefaultSelectedMenuItem(@Nullable() ContextualToolbarMenuItem defaultSelectedMenuItem)

        Sets an item that will be selected by default when this item is pressed. This method throws error if default selected menu item is not in the list of submenu items.

        Parameters:
        defaultSelectedMenuItem - Item to be selected by default, null for the owner to be selected.
      • setSelected

         void setSelected(boolean selected)

        Sets selected state to the item. Not applied if the item is not selectable.

        Parameters:
        selected - If true the item is selected, otherwise it's de-selected.
      • createSingleItem

         static ContextualToolbarMenuItem createSingleItem(@NonNull() Context context, @IdRes() int id, @NonNull() Drawable icon, @NonNull() String title, @ColorInt() int iconColor, @ColorInt() int iconColorActivated, @NonNull() ContextualToolbarMenuItem.Position position, boolean isSelectable)

        Creates a contextual toolbar menu single item with the provided properties. This is an image item

        Parameters:
        context - Context of the component creating the button.
        id - Menu item id.
        icon - Icon for the menu item.
        title - Menu item title.
        iconColor - Menu item color for default selected state (not selected).
        iconColorActivated - Menu item color for selected state (if possible).
        position - Position of the menu item in the toolbar.
        isSelectable - true if menu item can be selected, false if it can only be clicked.
      • shouldDisplayOutsideOfSubmenuIfPossible

         boolean shouldDisplayOutsideOfSubmenuIfPossible()

        Check whether this item can be expanded from submenu if there's room in the toolbar.

        Returns:

        true to enable showing action outside of it's group when toolbar has enough room to expand some items from submenu.

      • setSubMenuItems

         void setSubMenuItems(@Nullable() List<ContextualToolbarMenuItem> subMenuItems, @Nullable() ContextualToolbarMenuItem defaultSelectedMenuItem)

        Sets the submenu items to the menu item and a default selected item.

        Parameters:
        subMenuItems - Menu items to be displayed once this item is clicked, null if no owners.
        defaultSelectedMenuItem - Item to be selected by default, null for the owner to be selected.
      • setEnabled

         void setEnabled(boolean enabled)

        Sets the enabled state of this view. The interpretation of the enabled state varies by subclass.

        Parameters:
        enabled - true if this view is enabled, false otherwise.
      • setTintingEnabled

         void setTintingEnabled(boolean useTint)

        Sets whether the icon should be tinted in iconColor or left as originally provided.

        Parameters:
        useTint - If the tint should be used on the icon.
      • onLayoutChange

         void onLayoutChange(View view, int i, int i1, int i2, int i3, int i4, int i5, int i6, int i7)
      • onLongClick

         boolean onLongClick(View v)

        Called when a view has been clicked and held.

        Parameters:
        v - The view that was clicked and held.
        Returns:

        true if the callback consumed the long click, false otherwise.

      • hasSubmenu

         boolean hasSubmenu()

        Returns true if the menu item has a submenu.

      • shouldOpenSubmenuOnClick

         boolean shouldOpenSubmenuOnClick()

        Indicates whether the submenu should be opened after clicking on the menu item.

        Returns:

        true if the submenu should be opened after clicking on the menu item, false when the submenu should be opened only when long clicking on this menu item.

      • setCloseSubmenuOnItemClick

         void setCloseSubmenuOnItemClick(boolean shouldCloseSubmenuOnItemClick)

        Sets if the submenu should be hidden when any item in the submenu is clicked.

        Parameters:
        shouldCloseSubmenuOnItemClick - If true, clicking on the submenu item will close the submenu, otherwise it remains open.
      • setDisplayOutsideOfSubmenuIfPossible

         void setDisplayOutsideOfSubmenuIfPossible(boolean displayOutsideOfSubmenuIfPossible)

        Sets to display menu item as separate item outside of submenu if there's room in the toolbar.

        Parameters:
        displayOutsideOfSubmenuIfPossible - true to display as separate item if possible.
      • setOpenSubmenuOnClick

         void setOpenSubmenuOnClick(boolean openSubmenuOnClick)

        Sets if the submenu should be opened after clicking on the menu item.

        Note: This property is not used when menu item is selectable isSelectable. Clicking toggles selection in this case.

        Parameters:
        openSubmenuOnClick - If true and menu item is not selectable, clicking on the menu item will open its submenu.