I need to add a options menu for each fragment in bottom navigation view. currently each app bar has only the name of the fragment. I want to add specific options menu for each.
5
-
You no need to create appbar for every fragments... Try this stackoverflow.com/questions/8308695/…– Gobu CSGCommented Jul 10, 2022 at 7:08
-
@GobuCSG the code there seems to be deprecated. Is there a latest version.– UVicCommented Jul 10, 2022 at 14:49
-
It's not deprecated... Share those code here...– Gobu CSGCommented Jul 10, 2022 at 17:55
-
Yes it is .. Now you need to use menuProvider in each fragment .– UVicCommented Jul 11, 2022 at 5:29
-
@GobuCSG I have answered the question myself.. check it out.– UVicCommented Jul 11, 2022 at 5:32
Add a comment
|
1 Answer
Found solution [here]: 'setHasOptionsMenu(Boolean): Unit' is deprecated. Deprecated in Java
one thing I would like to add is so that the menu is removed when going to another fragment.
@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
requireActivity().removeMenuProvider(menuProvider);
}