动态启用/禁用隐藏/取消隐藏Android的动作条操作图标图标、动作、操作、动态

2023-09-12 02:42:25 作者:别来无恙你还狗样

我开发一个Android应用程序,它采用一个标准动作条。 某个用户屏幕上我有一个条件需要一个过滤器图标, 根据数据的特征被显示,如一些数据是可过滤 其他人没有。 我找不到动作条,看起来可能的候选人为programmaticaly任何方法 隐藏的动作条操作图标。 如何启用/禁用动作条操作图标? 或者 如何隐藏/取消隐藏的动作条操作图标?

I am developing an Android application that employs a standard ActionBar. on a certain screen i have a Filter icon that is conditionally required, depending on characteristics of the data being displayed, e.g. some data is filterable Others not. i cannot find any methods on actionbar that look likely candidates for programmaticaly hiding an actionbar action icon. how can i enable/disable an actionbar action icon? Or how can i hide/unhide an actionbar action icon?

推荐答案

看一看这一点,就说明了如何在运行时更改菜单项。

Have a look at this, it shows how to change menu items at runtime.

http://developer.android.com/guide/topics/ui/menus.html#ChangingTheMenu

例如,你可以保存菜单为您的活动里面onCreateOpionsMenu(成员变量),然后做这样的事情:

You could for example save the menu as a member variable of your Activity inside onCreateOpionsMenu() and then do something like this:

MenuItem item = mMenu.findItem(R.id.addAction);
item.doSomething()

当你想改变的东西在一个特定的菜单项

when you want to change something on a specific menu item.