0

I have tried to add options menu to my application, but when adding a Create Options Menu to the code it is not used. It looks like this:

IDE snapshot showing unused handler

I used in this page on Fragment Activity and implements Tab Listener.

What is the right way to add the Options Menu?

1 Answer 1

1

In the fragment activity where you want to have the menu (Make sure you are importing android.support.v4.app.FragmentActivity):

@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_menu, menu); return super.onCreateOptionsMenu(menu); } 

In res/menu folder you should have this file: main_menu.xml

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/itemId" android:icon="@drawable/ic_launcher" android:showAsAction="ifRoom|withText" android:title="@string/yourString"/> </menu> 
Sign up to request clarification or add additional context in comments.

5 Comments

thanks i try it but i get the error "cannot resolve the method getMenuInflater()"
I forgot you were using fragments. See my edited answer!
its not fragment its FragmentActivity.. so getActivity() method is not working in this case..
See my edited answer again, this soul work. It's working on my app right now using Fragment Activities
Did you check the import?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.