1@Override
2public boolean onCreateOptionsMenu(Menu menu) {
3 getMenuInflater().inflate(R.menu.main_menu, menu);
4 return true;
5}
1 // main xml
2 <androidx.appcompat.widget.Toolbar
3 android:id="@+id/activity_main_toolbar"
4 android:minHeight="?attr/actionBarSize"
5 android:layout_width="match_parent"
6 android:layout_height="wrap_content"
7 app:titleTextColor="@android:color/white"
8 android:background="?attr/colorPrimary"/>
9 // menu menu/..menu.xml
10
11 <menu xmlns:android="http://schemas.android.com/apk/res/android"
12 xmlns:app="http://schemas.android.com/apk/res-auto">
13 <item
14 android:id="@+id/menu_activity_main_search"
15 android:icon="@drawable/ic_search_white_24dp"
16 app:showAsAction="ifRoom"
17 android:title="Rechercher">
18 </item>
19 <item
20 android:id="@+id/menu_activity_main_params"
21 android:icon="@drawable/ic_more_vert_white_24dp"
22 app:showAsAction="ifRoom"
23 android:title="Paramètres">
24 </item>
25</menu>
26