Assign the LinearLayout identifier in the XML file:
<LinearLayout android:id="@+id/DrawerLinear" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> </LinearLayout>
Then in your java class, run this LinearLayout:
private LinearLayout DrawerLinear;
In OnCreate you should do this:
DrawerLinear = (LinearLayout) findViewById(R.id.DrawerLinear);
And in your onPrepareOptionMenu, put this:
public boolean onPrepareOptionsMenu(Menu menu) { boolean drawerOpen = mDrawerLayout.isDrawerOpen(DrawerLinear); menu.findItem(R.id.action_websearch).setVisible(!drawerOpen); return super.onPrepareOptionsMenu(menu); }
he should solve your problem.
source share