MenuProvider

Added in 1.7.0

public interface MenuProvider


Interface for indicating that a component will be supplying MenuItems to the component owning the app bar.

Summary

Public methods

abstract void
onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater)

Called by the MenuHost to allow the MenuProvider to inflate MenuItems into the menu.

default void

Called by the MenuHost when the Menu is closed.

abstract boolean

Called by the MenuHost when a MenuItem is selected from the menu.

default void

Called by the MenuHost right before the Menu is shown.

Public methods

onCreateMenu

Added in 1.7.0
abstract void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater)

Called by the MenuHost to allow the MenuProvider to inflate MenuItems into the menu.

Parameters
@NonNull Menu menu

the menu to inflate the new menu items into

@NonNull MenuInflater menuInflater

the inflater to be used to inflate the updated menu

onMenuClosed

Added in 1.8.0
default void onMenuClosed(@NonNull Menu menu)

Called by the MenuHost when the Menu is closed.

Parameters
@NonNull Menu menu

the menu that was closed

onMenuItemSelected

Added in 1.7.0
abstract boolean onMenuItemSelected(@NonNull MenuItem menuItem)

Called by the MenuHost when a MenuItem is selected from the menu.

Parameters
@NonNull MenuItem menuItem

the menu item that was selected

Returns
boolean

true if the given menu item is handled by this menu provider, false otherwise

onPrepareMenu

Added in 1.8.0
default void onPrepareMenu(@NonNull Menu menu)

Called by the MenuHost right before the Menu is shown. This should be called when the menu has been dynamically updated.

Parameters
@NonNull Menu menu

the menu that is to be prepared

See also
onCreateMenu