被supportInvalidateOptionsMenu()的工作? [英] Is supportInvalidateOptionsMenu() working?

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

问题描述

我有以下问题 - 我在我的应用程序更新动作条菜单中,经过一些事情发生。我使用 ActionBarActivity 从应用程序兼容性库。

I'm having the following issue - I have to update ActionBar menu in my application, after some things happen. I use ActionBarActivity from appcompat library.

所以,我叫 supportInvalidateOptionsMenu()的功能,但菜单不会更新。
在调试模式下我明白了,那onCreateOptionMenu方法调用,但菜单中没有改变。

So, I call supportInvalidateOptionsMenu() function, but menu won't update. In debug mode I see, that onCreateOptionMenu method is calling, but menu not changed.

我是不是做错了什么?还是它是 ActionBarActivity 问题?

Am I doing something wrong? Or does it is ActionBarActivity issue?

推荐答案

系统调用后 onCreateOptionsMenu(),它保留您填充并不会在菜单的一个实例叫 onCreateOptionsMenu()再次除非菜单是无效的某些原因。但是,你应该使用 onCreateOptionsMenu()只创建初始菜单状态,而不是活动生命周期中进行更改。

After the system calls onCreateOptionsMenu(), it retains an instance of the Menu you populate and will not call onCreateOptionsMenu() again unless the menu is invalidated for some reason. However, you should use onCreateOptionsMenu() only to create the initial menu state and not to make changes during the activity lifecycle.

如果你想修改基于活动的生命周期期间发生的事件的选项菜单中,您可以在上prepareOptionsMenu()办法做到这一点。因为它目前存在的,所以你可以修改它,如添加,删除或禁用物品此方法将你的菜单对象。 (片段还提供了一个上prepareOptionsMenu()回调)。

If you want to modify the options menu based on events that occur during the activity lifecycle, you can do so in the onPrepareOptionsMenu() method. This method passes you the Menu object as it currently exists so you can modify it, such as add, remove, or disable items. (Fragments also provide an onPrepareOptionsMenu() callback.)

在Android上的2.3.x版本和更低的系统调用 prepareOptionsMenu()每个用户打开选项菜单时(presses菜​​单按钮)。

On Android 2.3.x and lower, the system calls onPrepareOptionsMenu() each time the user opens the options menu (presses the Menu button).

在Android 3.0及更高版本,选项菜单被认为始终是打开的时候菜单项操作栏中的psented $ P $。当事件发生时,你要执行菜单更新,您必须调用 invalidateOptionsMenu()来请求该系统调用上prepareOptionsMenu( )

On Android 3.0 and higher, the options menu is considered to always be open when menu items are presented in the action bar. When an event occurs and you want to perform a menu update, you must call invalidateOptionsMenu() to request that the system call onPrepareOptionsMenu().

有关详细信息,点击这里

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

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