I'm trying to make a customized options menu. After using this code I get: Element item is not allowed here
Code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<item android:id="@+id/morsoid_settings"
android:icon="@drawable/ic_new_game"
android:title="@string/new_game" />
<item android:id="@+id/morsoid_close"
android:icon="@drawable/ic_help"
android:title="@string/help" />
</menu>
Inspired by: Android dev guide
I dont know whether it makes a difference, but did you place you menu in res/menu and not in res/layout?
Try leaving out the layout attributes. Here is the example from the documentation:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/new_game"
android:icon="@drawable/ic_new_game"
android:title="@string/new_game" />
<item android:id="@+id/help"
android:icon="@drawable/ic_help"
android:title="@string/help" />
</menu>
Edit - also make sure you are using a MenuInflater
as the guide suggests:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.game_menu, menu);
return true;
}
Using a LayoutInflater
will cause <menu>
to be interpreted as a view element, when it is actually a menu resource.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With