如何在android中的所有选项卡上禁用选项菜单中的特定选项?
我正在开发一个由四个选项卡组成的应用程序。它还有六个选项菜单,这是所有四个选项卡所共有的,我需要根据应用程序的当前状态禁用其中一个选项菜单。有什么方法可以禁用所有选项卡中选项菜单中的特定选项吗?
I am developing an application which consists of four tabs. Its also having six optionmenu which is common to all the four tabs and I need to disable one of the option menu depending on the current state of the application. Is there any way to disable particular option from the optionmenu across all the tabs??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要禁用菜单项,您可以在 Activity 中重写
onPrepareOptionsMenu
:如果您的选项卡由多个视图组成,则只需在一处重写该方法。如果您的选项卡由多个活动组成,那么您需要重写每个活动中的方法,并根据应用程序的状态选择要显示的项目。
To disable a menu item, you can override
onPrepareOptionsMenu
in your activity:If your tabs are composed of multiple views, then you only need to override the method in one place. If your tabs are composed of multiple activities, then you'll need to override the method in each of your activities and choose which items to display based on your application's state.