# MenuProvider

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/view/MenuProvider.java+class:androidx.core.view.MenuProvider) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

*** ** * ** ***


```
public interface MenuProvider
```

<br />

*** ** * ** ***

Interface for indicating that a component will be supplying `https://developer.android.com/reference/android/view/MenuItem.html`s to the component owning the app bar.

## Summary

| ### Public methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/core/view/MenuProvider#onCreateMenu(android.view.Menu,android.view.MenuInflater)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/Menu.html menu, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/MenuInflater.html menuInflater)` Called by the `https://developer.android.com/reference/androidx/core/view/MenuHost` to allow the `https://developer.android.com/reference/androidx/core/view/MenuProvider` to inflate `https://developer.android.com/reference/android/view/MenuItem.html`s into the menu. |
| `default void` | `https://developer.android.com/reference/androidx/core/view/MenuProvider#onMenuClosed(android.view.Menu)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/Menu.html menu)` Called by the `https://developer.android.com/reference/androidx/core/view/MenuHost` when the `https://developer.android.com/reference/android/view/Menu.html` is closed. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/core/view/MenuProvider#onMenuItemSelected(android.view.MenuItem)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/MenuItem.html menuItem)` Called by the `https://developer.android.com/reference/androidx/core/view/MenuHost` when a `https://developer.android.com/reference/android/view/MenuItem.html` is selected from the menu. |
| `default void` | `https://developer.android.com/reference/androidx/core/view/MenuProvider#onPrepareMenu(android.view.Menu)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/Menu.html menu)` Called by the `https://developer.android.com/reference/androidx/core/view/MenuHost` right before the `https://developer.android.com/reference/android/view/Menu.html` is shown. |

## Public methods

### onCreateMenu

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

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

Called by the `https://developer.android.com/reference/androidx/core/view/MenuHost` to allow the `https://developer.android.com/reference/androidx/core/view/MenuProvider` to inflate `https://developer.android.com/reference/android/view/MenuItem.html`s into the menu.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/Menu.html menu` | the menu to inflate the new menu items into |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/MenuInflater.html menuInflater` | the inflater to be used to inflate the updated menu |

### onMenuClosed

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/core#1.8.0)

```
default void onMenuClosed(@NonNull Menu menu)
```

Called by the `https://developer.android.com/reference/androidx/core/view/MenuHost` when the `https://developer.android.com/reference/android/view/Menu.html` is closed.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/Menu.html menu` | the menu that was closed |

### onMenuItemSelected

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

```
abstract boolean onMenuItemSelected(@NonNull MenuItem menuItem)
```

Called by the `https://developer.android.com/reference/androidx/core/view/MenuHost` when a `https://developer.android.com/reference/android/view/MenuItem.html` is selected from the menu.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/MenuItem.html 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](https://developer.android.com/jetpack/androidx/releases/core#1.8.0)

```
default void onPrepareMenu(@NonNull Menu menu)
```

Called by the `https://developer.android.com/reference/androidx/core/view/MenuHost` right before the `https://developer.android.com/reference/android/view/Menu.html` is shown. This should be called when the menu has been dynamically updated.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/Menu.html menu` | the menu that is to be prepared |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/view/MenuProvider#onCreateMenu(android.view.Menu,android.view.MenuInflater)` |   |