I want to add a menu to my Android project and I created a menu folder inside the res
folder, but got the error:
cannot resolve symbol 'menu'.
I was following an Android developers tutorial Menus | Android Developers
I will leave a screenshot of my project here: project
And here is the code:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.game_menu, menu);
return true;
}
game_menu.xml:
在 Android Studio 上的菜单 Build 中尝试清理和重建项目后。
Is that how you created it? you should try.
Res -> new -> Android Resource Directory -> Resource Type (Menu) -> Ok
Try to put it into one line of code like: getMenuInflater().inflate(R.menu.game_menu, menu);
First of all it is nicer coding I belive and that way we can be sure that the MenuInfalter is working. I have looked it up in my project and it is the same way there + working. If that does not help please share your game_menu.xml.
Use this code in your game_menu.xml
:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_settings"
android:orderInCategory="75"
android:title="my menu Item!"
app:showAsAction="never"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.