Bonjour,

Je ne vois pas trop comment mettre mon menu dans une classe pour ensuite le réutiliser dans mes activité.

Avant d'isoler mon menu, j'ai dans mon activité MainActivity, les fonctions suivantes :

onBackPressed, onCreateOptionsMenu, onOptionsItemSelected, onNavigationItemSelected.

Puis dans la fonction onCreate, j'ai :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
       setSupportActionBar(toolbar);
 
       DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
       ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
               this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
       drawer.setDrawerListener(toggle);
       toggle.syncState();
 
       NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
       navigationView.setNavigationItemSelectedListener(this);