Android: hide action bar menu views regardless the menu items -


i using navigation drawer switch between fragments. , action bar menu items different regarding fragments.

i want hide menu item views when drawer opened. referring doc, suggest find menu item id , hide item. however, menu items different fragments, so, how can hide/show menu item views on action bar? there flag control it?

by way, see in doc says can return false in onprepareoptionsmenu() make not displayed, tried , ended in vain. did misunderstand it?

public boolean onprepareoptionsmenu (menu menu) 

added in api level 1 prepare screen's standard options menu displayed. called right before menu shown, every time shown. can use method efficiently enable/disable items or otherwise dynamically modify contents. default implementation updates system menu items based on activity's state. deriving classes should call through base class implementation.

parameters menu options menu last shown or first initialized oncreateoptionsmenu().

returns must return true menu displayed; if return false not shown.

if people still visiting link, how disable options menu or options menu items fragment.

1) in oncreateview() method of fragment add following code

 sethasoptionsmenu(true);// can work menu items.without onprepareoptionsmenu() method not called  . 

now override onpreparedoptionsmenu() method , hide menu items. if hide menu items menu not @ shown. or use menu.clear() clear menu items

@override     public void onprepareoptionsmenu(menu menu) {         super.onprepareoptionsmenu(menu);         menu.finditem(r.id.menu_contacts).setvisible(false);         --------------         } 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -