其他分享
首页 > 其他分享> > android – onPrepareOptionsMenu有什么作用?

android – onPrepareOptionsMenu有什么作用?

作者:互联网

我想为Android制作选项菜单,我访问了这个网站.在他们的脚本中,我发现onPrepareOptionsMenu,我尝试使用Android 2.3.3编译器编译和运行,有和没有onPrepareOptionsMenu,两者都有效,但我没有看到任何区别.

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

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

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

什么是实际onPrepareOptionsMenu方法呢?这种方法很重要吗?我可以删除方法吗?

加成

哦,我也听说过Android 3.0中的Action Bar,它说Action Bar是制作Option Menu的另一种方式,它使用onPrepareOptionsMenu.那正确吗?

谢谢…

解决方法:

看看API

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.

标签:optionmenu,android,menu
来源: https://codeday.me/bug/20191005/1855116.html