Action Buttons Are Shown In All Fragments
I have included a menu in my fragment. But when going to other fragments(not overriding menu) in my viewpager the actions buttons remains the same (with all the actions) even when
Solution 1:
You need to call setHasOptionsMenu
from the Fragment
onCreateView
, to tell the Activity
that the Fragment has Option Menu. So that the onCreateOptionsMenu
will be called.
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragmentViewrow= inflater.inflate(R.layout.fragment_main, container, false);
setHasOptionsMenu(true);
return row;
}
And, In onCreateOptionsMenu
, just clear the menu items
@OverridepublicvoidonCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
super.onCreateOptionsMenu(menu, inflater);
}
Post a Comment for "Action Buttons Are Shown In All Fragments"