果冻豆不调用prepareOptionsMenu()打开菜单的时候第一次果冻、菜单、时候、prepareOptionsMenu

由网友(花有解语戏天涯°)分享简介:我就重写prepareOptionsMenu隐藏和显示菜单项。当API级别16模拟器测试它;在$ P首次打开菜单时$ ppareOptionsMenu不叫。但是,当我重​​新打开菜单它的作品。现在的问题是只与第一使用。有了这个,你可以简单的测试; I'm overriding onPrepareOptionsMenu...

我就重写prepareOptionsMenu隐藏和显示菜单项。当API级别16模拟器测试它;在$ P首次打开菜单时$ ppareOptionsMenu不叫。但是,当我重​​新打开菜单它的作品。现在的问题是只与第一使用。有了这个,你可以简单的测试;

I'm overriding onPrepareOptionsMenu to hide and show menu items. When testing it with the API level 16 emulator; onPrepareOptionsMenu is not called when opening the menu for the first time. But when i reopen the menu it works. The problem is only with the first usage. You can simple test it with this;

@Override
public void onPrepareOptionsMenu(Menu menu) {
    Toast.makeText(this.getActivity(), "pre", Toast.LENGTH_SHORT).show();
    super.onPrepareOptionsMenu(menu);
}

任何想法?

推荐答案

上prepareOptionsMenu()每个用户打开的姜饼和下方的菜单时,被称为。从蜂巢了选项菜单,假设永远是开放的,当项目都在ActionBar present。

onPrepareOptionsMenu() is called each time the user opens the menu on Gingerbread and below. From Honeycomb up the Options Menu is assumed to always be open when items are present in the ActionBar.

如果你想在你的活动生命周期和上prepareOptionsMenu()您需要调用回调中更新选项菜单 invalidateOptionsMenu ()上prepareOptionsMenu()将被调用。

If you want to update the Options Menu during your activities lifecyle and within the onPrepareOptionsMenu() callback you need to call invalidateOptionsMenu() and the onPrepareOptionsMenu() will be called.

你能不执行code在 onCreateOptionsMenu()回调您第一次使用?这就是所谓的每个选项菜单被创建时,它是在第一次使用创建的。

Could you not implement the code for your first usage in the onCreateOptionsMenu() callback? It is called every time the Options Menu is created and it is created on first use.

阅读全文

相关推荐

最新文章