gpt4 book ai didi

android - onCreateOptionsMenu 何时在启用 ActionBar 的 Activity 中发生?

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:07:06 27 4
gpt4 key购买 nike

我知道菜单项将在 ActionBar 中设置为操作图标。

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

根据我的测试,它甚至在 onResume 之后也没有

最佳答案

文档说明如下:

public boolean onCreateOptionsMenu (Menu menu)

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

这里有进一步的解释:http://developer.android.com/reference/android/app/Activity.html#onCreateOptionsMenu%28android.view.Menu%29

并引用 CommonsWare 在另一个相关问题上发表的内容:

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

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: When is onCreateOptionsMenu called during Activity lifecycle?

关于android - onCreateOptionsMenu 何时在启用 ActionBar 的 Activity 中发生?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9492333/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com