Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在运行访问菜单项之一的特定代码之前,我需要确保已创建选项菜单。是否有回调或我该如何实现?
是否有任何保证菜单已在活动的 onResume() 上创建?
它不是 onCreateOptionsMenu 完成后的回调,但是如果你想在菜单显示之前进行修改,可以使用 onPrepareOptionsMenu 进行修改。这只会在 onCreateOptionsMenu 之后调用(如果 Android 正在运行,则应该这样做)。
http://developer.android.com/reference/android/app/Activity.html#onPrepareOptionsMenu(android.view.Menu)
请参阅有关此的活动文档:
http://developer.android.com/reference/android/app/Activity.html#onCreateOptionsMenu(android.view.Menu )