onCreateOptionsMenu 何时在启用 ActionBar 的活动中发生? [英] When does onCreateOptionsMenu happen in an ActionBar enabled activity?

查看:29
本文介绍了onCreateOptionsMenu 何时在启用 ActionBar 的活动中发生?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道菜单项将被设置为 ActionBar 中的操作图标.

I know the menu item will be set as action icons in the ActionBar.

我想确切地知道这个 onCreateOptionsMenu 函数,它什么时候在 Activity 生命周期中调用.

I want to know exactly this onCreateOptionsMenu function, when does it called in the activity lifecycle.

从我的测试来看,即使在 onResume 之后也没有

From my test, it does not even after onResume

推荐答案

文档说明如下:

public boolean onCreateOptionsMenu (Menu menu)

初始化活动标准选项菜单的内容.您应该将菜单项放入菜单中.这是只调用一次,第一次显示选项菜单.要在每次显示时更新菜单,请参阅 onPrepareOptionsMenu(Menu).

Initialize the contents of the Activity's standard options menu. You should place your menu items in to menu. This is only called once, the first time the options menu is displayed. To update the menu every time it is displayed, see onPrepareOptionsMenu(Menu).

此处进一步解释:http://developer.android.com/reference/android/app/Activity.html#onCreateOptionsMenu%28android.view.Menu%29

并引用 CommonsWare 在另一个相关问题上的说明:

And quoting what CommonsWare put on another related question:

首先调用 onCreate 方法,在它完成之前调用 onCreateOptionsMenu.

The onCreate method is called first, and before it finishes onCreateOptionsMenu is called.

在带有官方 Honeycomb 样式操作栏的设备和应用程序上也是如此.如果没有操作栏,则在用户调用菜单(通常是按 MENU 按钮)之前不应调用 onCreateOptionsMenu().

That will be true on devices and apps with an official Honeycomb-style action bar. If there is no action bar, onCreateOptionsMenu() should not get called until the user calls up the menu, typically by pressing the MENU button.

此处链接:Android:在 Activity 生命周期中 onCreateOptionsMenu 何时被调用?

这篇关于onCreateOptionsMenu 何时在启用 ActionBar 的活动中发生?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆