onCreateOptionsMenu 第一次创建时调用
onPrepareOptionsMenu 运行时每次点击菜单按钮时都会调用这个函数,可以动态改变菜单项
public boolean onPrepareOptionsMenu (Menu menu)
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. The default implementation
updates the system menu items based on the activity's state. Deriving classes should always call through to the base class implementation.
注意:在onPrepareOptionsMenu(Menumenu)函数中,首先需要调用:
super.onPrepareOptionsMenu(menu);
menu.clear();
如果没有clear而直接add的话,那么菜单项会不断增加