0

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 CSG
    Commented Jul 10, 2022 at 7:08
  • @GobuCSG the code there seems to be deprecated. Is there a latest version.
    – UVic
    Commented Jul 10, 2022 at 14:49
  • It's not deprecated... Share those code here...
    – Gobu CSG
    Commented Jul 10, 2022 at 17:55
  • Yes it is .. Now you need to use menuProvider in each fragment .
    – UVic
    Commented Jul 11, 2022 at 5:29
  • @GobuCSG I have answered the question myself.. check it out.
    – UVic
    Commented Jul 11, 2022 at 5:32

1 Answer 1

0

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);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.