onPrepareOptionsMenu有什么作用? [英] What does onPrepareOptionsMenu do?

查看:133
本文介绍了onPrepareOptionsMenu有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为Android制作Option Menu,我已经访问了此站点.在他们的脚本中,我找到了onPrepareOptionsMenu,我尝试使用带或不带onPrepareOptionsMenu的Android 2.3.3编译器进行编译和运行,两者都可以,但是我看不出有什么区别.

I want to make Option Menu for Android, I have visit this site. In their script, I found onPrepareOptionsMenu, I try to compile and run using Android 2.3.3 compiler with and without onPrepareOptionsMenu, both works, but I didn't see any difference.

public boolean onCreateOptionsMenu(Menu menu){
//code here
}

public boolean onOptionsItemSelected(MenuItem item){
//code here
}

public boolean onPrepareOptionsMenu(Menu menu){
//code here
}

onPrepareOptionsMenu方法实际上是做什么的?那方法重要吗?我可以删除该方法吗?

What is actually onPrepareOptionsMenu method do? Is that method important? Could I just delete the method?

添加

哦,我也听说过Android 3.0中的Action Bar,它说操作栏是制作Option Menu的替代方法,并且它使用onPrepareOptionsMenu.是吗?

Oh, I also hear about Action Bar in Android 3.0, it says that Action Bar is the alternative way for make Option Menu, and it using onPrepareOptionsMenu. Is that right?

谢谢...

推荐答案

准备要显示的屏幕标准选项菜单.在显示菜单之前,每次显示菜单时都会调用此方法.您可以使用此方法有效地启用/禁用项目,或以其他方式动态地修改内容.

Prepare the Screen's standard options menu to be displayed. This is called right before the menu is shown, every time it is shown. You can use this method to efficiently enable/disable items or otherwise dynamically modify the contents.

这篇关于onPrepareOptionsMenu有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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