Java Code Examples for androidx.appcompat.widget.Toolbar#getMenu()

The following examples show how to use androidx.appcompat.widget.Toolbar#getMenu() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Inflates the menu of the toolbar, which is shown, when the tab switcher is shown.
 */
private void inflateToolbarMenu() {
    Toolbar[] toolbars = getToolbars();
    int menuId = getModel().getToolbarMenuId();

    if (toolbars != null && menuId != -1) {
        Toolbar toolbar = toolbars.length > 1 ? toolbars[TabSwitcher.SECONDARY_TOOLBAR_INDEX] :
                toolbars[TabSwitcher.PRIMARY_TOOLBAR_INDEX];
        Menu previousMenu = toolbar.getMenu();

        if (previousMenu != null) {
            previousMenu.clear();
        }

        toolbar.inflateMenu(menuId);
        toolbar.setOnMenuItemClickListener(getModel().getToolbarMenuItemListener());
    }
}
 
Example 2
Source File: MoodleFragment.java    From ETSMobile-Android2 with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    final Toolbar toolbar = ((MainActivity) getActivity()).getToolbar();
    toolbar.inflateMenu(R.menu.menu_moodle);
    this.menu = toolbar.getMenu();

    super.onCreateOptionsMenu(this.menu, inflater);

    if (menu.findItem(R.id.menu_item_moodle_assignments) != null && !moodleViewModel.isShowCaseHasBeenDisplayed()) {
        new Handler().post(() -> {
            try {
                TapTargetView.showFor(getActivity(), TapTarget.forToolbarMenuItem(toolbar,
                        R.id.menu_item_moodle_assignments,
                        getString(R.string.moodle_assignments_title),
                        getString(R.string.moodle_assignments_description)));
                moodleViewModel.setShowCaseHasBeenDisplayed(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
}
 
Example 3
Source File: AbstractTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public final Menu getToolbarMenu() {
    Toolbar[] toolbars = getToolbars();

    if (toolbars != null) {
        Toolbar toolbar = toolbars.length > 1 ? toolbars[TabSwitcher.SECONDARY_TOOLBAR_INDEX] :
                toolbars[TabSwitcher.PRIMARY_TOOLBAR_INDEX];
        return toolbar.getMenu();
    }

    return null;
}