什么时候以及多久为ActionBar调用一次onPrepareOptionsMenu()方法? [英] When and how often is the onPrepareOptionsMenu() method called for ActionBar?

查看:84
本文介绍了什么时候以及多久为ActionBar调用一次onPrepareOptionsMenu()方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Activities很明显-在显示菜单之前就正在调用该方法.但是ActionBar总是显示 怎么办?如何触发它以动态更新menuItems?

It is clear for Activities - the method is being called right before the menu is shown. But what about ActionBar when it is always shown? How to trigger it to be invoked to dynamically update menuItems?

推荐答案

使用invalidateOptionsMenu()触发文档建议的onPrepareOptionMenu()方法.

Use invalidateOptionsMenu() to trigger onPrepareOptionMenu() method as suggested by document.

On Android 3.0 and higher, you must call invalidateOptionsMenu() when you want to update the menu, because the menu is always open. The system will then call onPrepareOptionsMenu() so you can update the menu items.

这篇关于什么时候以及多久为ActionBar调用一次onPrepareOptionsMenu()方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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