MenuHost

public interface MenuHost

androidx.core.view.MenuHost


A class that allows you to host and keep track of MenuProviders that will supply MenuItems to the app bar.

See also:

Summary

Public methods

abstract void addMenuProvider(MenuProvider provider)

Adds the given MenuProvider to this MenuHost.

abstract void addMenuProvider(MenuProvider provider, LifecycleOwner owner, Lifecycle.State state)

Adds the given MenuProvider to this MenuHost once the given LifecycleOwner reaches the given Lifecycle.State.

abstract void addMenuProvider(MenuProvider provider, LifecycleOwner owner)

Adds the given MenuProvider to this MenuHost.

abstract void invalidateMenu()

Invalidates the Menu to ensure that what is displayed matches the current internal state of the menu.

abstract void removeMenuProvider(MenuProvider provider)

Removes the given MenuProvider from this MenuHost.

Public methods

addMenuProvider

public abstract void addMenuProvider (MenuProvider provider)

Adds the given MenuProvider to this MenuHost. If using this method, you must manually remove the provider when necessary.

Parameters
provider MenuProvider: the MenuProvider to be added

addMenuProvider

public abstract void addMenuProvider (MenuProvider provider, 
                LifecycleOwner owner, 
                Lifecycle.State state)

Adds the given MenuProvider to this MenuHost once the given LifecycleOwner reaches the given Lifecycle.State. This MenuProvider will be removed once the given LifecycleOwner goes down from the given Lifecycle.State.

Parameters
provider MenuProvider: the MenuProvider to be added

owner LifecycleOwner: the Lifecycle owner whose state will be used for automated addition/removal

state Lifecycle.State: the Lifecycle.State to check for automated addition/removal

addMenuProvider

public abstract void addMenuProvider (MenuProvider provider, 
                LifecycleOwner owner)

Adds the given MenuProvider to this MenuHost. This MenuProvider will be removed once the given LifecycleOwner receives an ERROR(/Lifecycle.Event.ON_DESTROY) event.

Parameters
provider MenuProvider: the MenuProvider to be added

owner LifecycleOwner: the Lifecycle owner whose state will determine the removal of the provider

invalidateMenu

public abstract void invalidateMenu ()

Invalidates the Menu to ensure that what is displayed matches the current internal state of the menu. This should be called whenever the state of the menu is changed, such as items being removed or disabled based on some user event.

removeMenuProvider

public abstract void removeMenuProvider (MenuProvider provider)

Removes the given MenuProvider from this MenuHost.

Parameters
provider MenuProvider: the MenuProvider to be removed