public class

SubMenuBuilder

extends MenuBuilder

 java.lang.Object

androidx.appcompat.view.menu.MenuBuilder

↳androidx.appcompat.view.menu.SubMenuBuilder

Gradle dependencies

compile group: 'androidx.appcompat', name: 'appcompat', version: '1.7.0'

  • groupId: androidx.appcompat
  • artifactId: appcompat
  • version: 1.7.0

Artifact androidx.appcompat:appcompat:1.7.0 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.appcompat:appcompat com.android.support:appcompat-v7

Androidx class mapping:

androidx.appcompat.view.menu.SubMenuBuilder android.support.v7.view.menu.SubMenuBuilder

Overview

The model for a sub menu, which is an extension of the menu. Most methods are proxied to the parent menu.

Summary

Constructors
publicSubMenuBuilder(Context context, MenuBuilder parentMenu, MenuItemImpl item)

Methods
public booleancollapseItemActionView(MenuItemImpl item)

public booleanexpandItemActionView(MenuItemImpl item)

public java.lang.StringgetActionViewStatesKey()

public MenuItemgetItem()

public MenugetParentMenu()

public MenuBuildergetRootMenu()

Gets the root menu (if this is a submenu, find its root menu).

public booleanisGroupDividerEnabled()

booleanisQwertyMode()

public booleanisShortcutsVisible()

public voidsetCallback(MenuBuilder.Callback callback)

public voidsetGroupDividerEnabled(boolean groupDividerEnabled)

public SubMenusetHeaderIcon(Drawable icon)

public SubMenusetHeaderIcon(int iconRes)

public SubMenusetHeaderTitle(java.lang.CharSequence title)

public SubMenusetHeaderTitle(int titleRes)

public SubMenusetHeaderView(View view)

public SubMenusetIcon(Drawable icon)

public SubMenusetIcon(int iconRes)

public voidsetQwertyMode(boolean isQwerty)

public voidsetShortcutsVisible(boolean shortcutsVisible)

Sets whether the shortcuts should be visible on menus.

from MenuBuilderadd, add, add, add, addIntentOptions, addInternal, addMenuPresenter, addMenuPresenter, addSubMenu, addSubMenu, addSubMenu, addSubMenu, changeMenuMode, clear, clearAll, clearHeader, close, close, findGroupIndex, findGroupIndex, findItem, findItemIndex, flagActionItems, getActionItems, getContext, getExpandedItem, getHeaderIcon, getHeaderTitle, getHeaderView, getItem, getNonActionItems, getVisibleItems, hasVisibleItems, isDispatchingItemsChanged, isShortcutKey, onItemsChanged, performIdentifierAction, performItemAction, performItemAction, performShortcut, removeGroup, removeItem, removeItemAt, removeMenuPresenter, restoreActionViewStates, restorePresenterStates, saveActionViewStates, savePresenterStates, setCurrentMenuInfo, setDefaultShowAsAction, setGroupCheckable, setGroupEnabled, setGroupVisible, setHeaderIconInt, setHeaderTitleInt, setHeaderTitleInt, setHeaderViewInt, setOptionalIconsVisible, setOverrideVisibleItems, size, startDispatchingItemsChanged, stopDispatchingItemsChanged
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public SubMenuBuilder(Context context, MenuBuilder parentMenu, MenuItemImpl item)

Methods

public void setQwertyMode(boolean isQwerty)

boolean isQwertyMode()

Returns:

whether the menu shortcuts are in qwerty mode or not

public void setShortcutsVisible(boolean shortcutsVisible)

Sets whether the shortcuts should be visible on menus. Devices without hardware key input will never make shortcuts visible even if this method is passed 'true'.

Parameters:

shortcutsVisible: Whether shortcuts should be visible (if true and a menu item does not have a shortcut defined, that item will still NOT show a shortcut)

public boolean isShortcutsVisible()

Returns:

Whether shortcuts should be visible on menus.

public Menu getParentMenu()

public MenuItem getItem()

public void setCallback(MenuBuilder.Callback callback)

public MenuBuilder getRootMenu()

Gets the root menu (if this is a submenu, find its root menu).

Returns:

The root menu.

public SubMenu setIcon(Drawable icon)

public SubMenu setIcon(int iconRes)

public SubMenu setHeaderIcon(Drawable icon)

public SubMenu setHeaderIcon(int iconRes)

public SubMenu setHeaderTitle(java.lang.CharSequence title)

public SubMenu setHeaderTitle(int titleRes)

public SubMenu setHeaderView(View view)

public boolean expandItemActionView(MenuItemImpl item)

public boolean collapseItemActionView(MenuItemImpl item)

public java.lang.String getActionViewStatesKey()

public void setGroupDividerEnabled(boolean groupDividerEnabled)

public boolean isGroupDividerEnabled()

Source

/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.appcompat.view.menu;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;

/**
 * The model for a sub menu, which is an extension of the menu.  Most methods are proxied to the
 * parent menu.
 *
 */
@RestrictTo(LIBRARY_GROUP_PREFIX)
public class SubMenuBuilder extends MenuBuilder implements SubMenu {
    private MenuBuilder mParentMenu;
    private MenuItemImpl mItem;

    public SubMenuBuilder(Context context, MenuBuilder parentMenu, MenuItemImpl item) {
        super(context);

        mParentMenu = parentMenu;
        mItem = item;
    }

    @Override
    public void setQwertyMode(boolean isQwerty) {
        mParentMenu.setQwertyMode(isQwerty);
    }

    @Override
    public boolean isQwertyMode() {
        return mParentMenu.isQwertyMode();
    }

    @Override
    public void setShortcutsVisible(boolean shortcutsVisible) {
        mParentMenu.setShortcutsVisible(shortcutsVisible);
    }

    @Override
    public boolean isShortcutsVisible() {
        return mParentMenu.isShortcutsVisible();
    }

    public Menu getParentMenu() {
        return mParentMenu;
    }

    @Override
    public MenuItem getItem() {
        return mItem;
    }

    @Override
    public void setCallback(Callback callback) {
        mParentMenu.setCallback(callback);
    }

    @Override
    public MenuBuilder getRootMenu() {
        return mParentMenu.getRootMenu();
    }

    @Override
    boolean dispatchMenuItemSelected(@NonNull MenuBuilder menu, @NonNull MenuItem item) {
        return super.dispatchMenuItemSelected(menu, item) ||
                mParentMenu.dispatchMenuItemSelected(menu, item);
    }

    @Override
    public SubMenu setIcon(Drawable icon) {
        mItem.setIcon(icon);
        return this;
    }

    @Override
    public SubMenu setIcon(int iconRes) {
        mItem.setIcon(iconRes);
        return this;
    }

    @Override
    public SubMenu setHeaderIcon(Drawable icon) {
        return (SubMenu) super.setHeaderIconInt(icon);
    }

    @Override
    public SubMenu setHeaderIcon(int iconRes) {
        return (SubMenu) super.setHeaderIconInt(iconRes);
    }

    @Override
    public SubMenu setHeaderTitle(CharSequence title) {
        return (SubMenu) super.setHeaderTitleInt(title);
    }

    @Override
    public SubMenu setHeaderTitle(int titleRes) {
        return (SubMenu) super.setHeaderTitleInt(titleRes);
    }

    @Override
    public SubMenu setHeaderView(View view) {
        return (SubMenu) super.setHeaderViewInt(view);
    }

    @Override
    public boolean expandItemActionView(MenuItemImpl item) {
        return mParentMenu.expandItemActionView(item);
    }

    @Override
    public boolean collapseItemActionView(MenuItemImpl item) {
        return mParentMenu.collapseItemActionView(item);
    }

    @Override
    public String getActionViewStatesKey() {
        final int itemId = mItem != null ? mItem.getItemId() : 0;
        if (itemId == 0) {
            return null;
        }
        return super.getActionViewStatesKey() + ":" + itemId;
    }

    @Override
    public void setGroupDividerEnabled(boolean groupDividerEnabled) {
        mParentMenu.setGroupDividerEnabled(groupDividerEnabled);
    }

    @Override
    public boolean isGroupDividerEnabled() {
        return mParentMenu.isGroupDividerEnabled();
    }
}