Aracılığıyla paylaş


Activity.OnCreateOptionsMenu(IMenu) Method

Definition

Initialize the contents of the Activity's standard options menu.

[Android.Runtime.Register("onCreateOptionsMenu", "(Landroid/view/Menu;)Z", "GetOnCreateOptionsMenu_Landroid_view_Menu_Handler")]
public virtual bool OnCreateOptionsMenu (Android.Views.IMenu? menu);
[<Android.Runtime.Register("onCreateOptionsMenu", "(Landroid/view/Menu;)Z", "GetOnCreateOptionsMenu_Landroid_view_Menu_Handler")>]
abstract member OnCreateOptionsMenu : Android.Views.IMenu -> bool
override this.OnCreateOptionsMenu : Android.Views.IMenu -> bool

Parameters

menu
IMenu

The options menu in which you place your items.

Returns

You must return true for the menu to be displayed; if you return false it will not be shown.

Attributes

Remarks

Initialize the contents of the Activity's standard options menu. You should place your menu items in to <var>menu</var>.

This is only called once, the first time the options menu is displayed. To update the menu every time it is displayed, see #onPrepareOptionsMenu.

The default implementation populates the menu with standard system menu items. These are placed in the Menu#CATEGORY_SYSTEM group so that they will be correctly ordered with application-defined menu items. Deriving classes should always call through to the base implementation.

You can safely hold on to <var>menu</var> (and any items created from it), making modifications to it as desired, until the next time onCreateOptionsMenu() is called.

When you add items to the menu, you can implement the Activity's #onOptionsItemSelected method to handle them there.

Java documentation for android.app.Activity.onCreateOptionsMenu(android.view.Menu).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

See also