java - Toolbar items shown only in activity_main -


i've got menu_main.xml works activity_main.xml. how make menu_main.xml works elswhere in 1 activity? when change content view layout toolbar items menu_main disappears , leaves me empty app_bar.

menu_main.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"      xmlns:tools="http://schemas.android.com/tools" tools:context=".przepisy">      <item android:id="@+id/action_settings" android:title="@string/action_settings"         android:orderincategory="100" app:showasaction="never" />  </menu> 

main.java:

@override     public boolean oncreateoptionsmenu(menu menu) {         getmenuinflater().inflate(r.menu.menu_przepisy, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         int id = item.getitemid();          if (id == r.id.action_settings) {             return true;         }           return super.onoptionsitemselected(item);     } 

androidmainfest.xml:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.ambu.przepisy" >      <application         android:allowbackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:supportsrtl="true"         android:theme="@style/apptheme" >         <activity             android:name=".przepisy"             android:label="@string/app_name"             android:theme="@style/apptheme" >             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>     </application>  </manifest> 

you need add
getmenuinflater().inflate(r.menu.menu_przepisy, menu); return true; activities want menu. inside oncreateoptionsmenu(menu menu) method.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -