A menu of custom options for each fragment

I have a problem. I am trying to change the default options menu, different for each fragment. I created an xml file for each fragment, and I put them in the res / menu folder. Now I donโ€™t know how to tell android to change the default settings menu in each fragment. I put the snippet in the pager view. The menu I'm talking about is the one below, next to the home and back buttons.

this is one of the custom menus

<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context="com.example.prova.Frase" > <item android:id="@+id/one" android:title="Scatta Foto"/> <item android:id="@+id/two" android:title="Scegli dal Rullino"/> <item android:id="@+id/three" android:title="Prossimo sfondo predefinito"/> </menu> 
+5
source share
2 answers

on each snippet you must override onCreateOptionsMenu . Remember to call setHasOptionsMenu(true); (in onCreate for example.). Here you can find onCreateOptionsMenu documentation

0
source

You can override onCreateOptionsMenu in each of the fragments. Hope this helps

 @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.fragMenu, menu); this.menu = menu; } 
0
source

Source: https://habr.com/ru/post/1208868/


All Articles