Skip to content
Advertisement

How can I change option menu in different fragments?

I have a Fragment with menu:

JavaScript

I would like to change menu but it doesn’t work and keep the old action menu

Fragment B is equals like above with different inflate XML menu.

JavaScript

EDITED:

Can be useful to use different menu layout for different fragments and 1 menu layout for main activity and differents id

Advertisement

Answer

Put setHasOptionsMenu(true) in constructor and inflate fragment specific menu.

JavaScript

menu in main activity

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement