Android get a View reference to action bar item?

You can do menu.findItem( to get the menu item, and you can get reference to menu object in your onCreateOptionsMenu(Menu menu) method then you can initialize a global variable with that menu object to use it anywhere.

Here is some code:

public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(, menu);
    _menu = menu;
    return true;

I am initialize my global variable Menu _menu; with menu object and then i can do like this MenuItem mi = _menu.findItem(; any where i want.

Please take care that you are not calling anything on menuitem before the menu gets created, you can schedule a thread to wait for 3 to 5 secs or you can do it some other way, all you should worry about is whether the menu has been initialized or not.

Leave a Comment