如何使一个动态的选项菜单?
问题描述:
问题是,下面的方法被调用一次时,菜单按钮是pressed:
The problem is that the following method gets called one time when the Menu button is pressed:
public boolean onCreateOptionsMenu(Menu menu)
我怎样才能重新在以后的时间,以改变一些选项的菜单,禁用某些选项,等等?
How can I recreate the menu at a later time in order to change some options, disable some options, etc?
答
覆盖此 在prepareOptionsMenu(功能菜单)
Override this onPrepareOptionsMenu(Menu menu)
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem item = menu.findItem(R.id.refresh);
if (item != null) {
item.setVisible (shouldIShowThisItem)
}
}