android中invalidateOptionsMenu()的用法 [英] What is the use of invalidateOptionsMenu() in android

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

问题描述

当我浏览导航抽屉的示例代码时,我是android的新手,我发现他调用了invalidateOptionsMenu()方法,因此我搜索了其功能,但找不到答案,因此任何人都可以向我简要介绍一下其功能以及何时应该使用它.

I am a newbie to android when I am going through a sample code for navigation drawer I found he called the method invalidateOptionsMenu() so I searched regarding its functionality but couldn't find an answer so can anyone please brief me its functionality and whenshould we use that.

推荐答案

此函数告诉android应该重绘菜单.默认情况下,一旦创建菜单,就不会在每一帧都重新绘制菜单(因为这样一遍又一遍地重新绘制同一菜单是没有用的.)

This function tell android that it should redraw the menu. By default, once the menu is created, it won't be redrawn every frame (since that would be useless to redraw the same menu over and over again).

在选项菜单中进行了某些更改(添加元素,删除元素或更改文本)时,应调用此函数.这样,android将知道是时候重新绘制菜单,您的更改才会出现.

You should call this function when you changed something in the option menu (added an element, deleted an element or changed a text). This way android will know that it's time te redraw the menu and your change will appear.

希望这能回答您的问题

这篇关于android中invalidateOptionsMenu()的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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